How to get an elapsed time for this? - java

I am creating a Spigot (Performance savvy fork of Bukkit (Minecraft server software)) plugin that communicates with a Bungee (Proxy server for managing multiple spigot instances) server.
I have a functionality, that when you type a command "/setbar (time-in-seconds) (message)", it will use an API (BarAPI if you are familiar) to create a bar on every server connected to the Bungee instance.
The fault with this is that when a player joins one of the Spigot servers after the command was issued, the Bar is not there. I solve this by storing the bar's information on the Proxy level and sending these values to the specific Spigot instance the player attempts to join.
Okay, so enough background information. The problem I'm having is that I'm storing the time the admin (or whoever issued the command) requested in a variable. When the user joins, obviously the time will have decremented slightly (or a lot.) The way I've thought of making sure the user who is joining receives the proper elapsed time, (so the BarAPI knows how large the timer graphic needs to be), was by storing the time the command was executed in a variable (currentTimeMillis / currentTimeNano) and converting that to seconds then subtracting that from the time specified in the command.
I know there is a flaw with my logic here, and I can't seem to work out the math. I know this is rather simple, but any help you can provide would be extremely beneficial.
Thanks in advance.
Postscript: Any information I have failed to provide, please let me know and I will add it to this post.

I realize this is a bit of a "no-end" question as there isn't an exact answer provided I didn't actually give any code.
Here is how I solved it in plain English, though:
Store the time the command was executed the first in milliseconds.
When the command is executed next, remove the first value from the new value and divide it by 1000 to receive a seconds-value.
The seconds-value is the elapsed time. Once can find how much time is remaining by then subtracting the seconds-value from the initially provided seconds-value for the bar.
Erase the bar for the user in question; recreate same values but substitute seconds for the newly calculated seconds-value.

Related

Uncommon question with "Ethical hacking" challenge

I have a rather unusual question, but I still don't understand much in programming to understand if it is possible to do what I want. So I feel like I need a little story. My name is Nick, I live in Ukraine and am currently studying as a student in one of the IT firms. Now is the middle of my studies and, if everything goes good, they will give me a chance to get a job in 2 months. But not only me, but 300 more students from all over the country, since the training is online, and the company in which we will get one of the largest in the CIS.
This is where I come closer to the task. To complete the course, we have to complete 8 practical sessions with 5-6 tasks in each. Upon their implementation, we upload the code to the git lab. For this, the company has opened an account for each of us. Then the electronic program for checking assignments - E-Mentor compiles our code, provides input data to fill each class and checks the task. In case of an error, it creates log, which often does not provide complete information. Since some of the test data is always hidden. At the end, the program sets progress points for us. And we all want to get 100%)
**Task: Get input data from the E-Mentor server in the form of a file and automatically push it from the server side to my Git Lab account.**
I am not asking for the complete code, but I am asking you to help me write pseudo code so that I can implement it in full.
I represent it like this:
The server clones my code
Compiles it
Runs tests
At this time, a file is created that copies all incoming information from tests
Somehow the created file is being pushed to my gitlab
For example:
GitBash is started on the server and logs into the gitlab under my login. In this case, it is restricted to rewrite the password and login used by the server itself, as it will be immediately noticed.
This is the coolest challenge that I want to try to do and share it with all students)

How to clear unwanted records in Kinvey Database

I am having an Android app and I am planning to use Kinvey Database to store some data.
One of the record in the entry would be having the last used time period.
The last used time period will be set by my app when ever the app is opened.
What basically I am trying to achieve is to run a code at the end of each month and clear all the record whos value of the last used period is more than 10 days.
Can any one please tell me whether it is possible to do this?
The reason for doing this is to use the least Server storage space as they provide only 1 GB/Monthly in the free plan.
What I understand from this...
What basically I am trying to achieve is to run a code at the end of each month and clear all the record whos value of the last used period is more than 10 days.
Can any one please tell me whether it is possible to do this?
... is that you would like to have scheduled code, which will be executed once a month. Please take a further look at the Scheduled Code feature of Kinvey.
https://devcenter.kinvey.com/html5/tutorials/scheduled-code-getting-started
Edit: more information on the topic...
Kinvey Scheduled code allows you to execute one of your custom endpoints on a specific date in the future. It is commonly used to
Aggregate, archive, and cleanup data.
Pull data from a third-party API into Kinvey.
Send out a batch of e-mails or push notifications.
I would not bother describing step-by-step initializing of Scheduled Code, since those steps may change in the future. Please follow the steps from the link above, those should be fine to get you further.

How to handle a large datalogger csv file / playback in java

I have a datalogger that produces a CSV file containing UTC time and 4 parameters. The UTC time is logged ABOUT every 30ms followed by the 4 parameters. The problem I have is 2 fold:
1) The CSV file is potentially huge if I run the datalogger for even an hour.
2) The UTC time is not exactly every 30ms.
In my simple design for a replay of the data I had planned to load the file, split each entry at character "'" then assign the values in a loop though the UTC time value and then load the 4 parameters, but with the file so large I am concerned it wont work or will be very slow. I am new to java and am not sure if the there is a better way to handle so much data (I suspect there is!).
My plan to loop through and repeat he filling of 4 variables for the parameters wont work as the UTC entries are not exact. I had planned to take a decimal place off the data, but that clearly looses me fidelity in the replay of my data. I want to be able to construct a "timeline" in my application to allow play pause stop style functionality hence my problem handling the UTC time.
Here is a sample of some of the data when the time is pretty tight, this isnt always the case:
,13:35:38.772,0,0,0,0.3515625
,13:35:38.792,0,0,-0.0439453125,0.3515625
,13:35:38.822,0,0,0,0.3515625
,13:35:38.842,0,0,0,0.3515625
,13:35:38.872,0,0,0.0439453125,0.3515625
,13:35:38.892,0,0,0,0.3076171875
,13:35:38.922,0,0,0,0.3076171875
,13:35:38.942,0,0,0,0.3076171875
,13:35:38.962,0,0,0.0439453125,0.3515625
,13:35:38.992,0,0,0,0.3515625
,13:35:39.012,0,0,0,0.3076171875
,13:35:39.042,0,0,-0.0439453125,0.3076171875
,13:35:39.072,0,0,0,0.3515625
,13:35:39.092,0,0,0,0.3515625
,13:35:39.112,0,0,0.0439453125,0.3076171875
,13:35:39.142,0,0,0,0.3515625
,13:35:39.162,0,0,0,0.3076171875
,13:35:39.192,0,0,0,0.3515625
,13:35:39.212,0,0,0,0.3076171875
,13:35:39.242,0,0,0,0.3515625
,13:35:39.262,0,0,0,0.3076171875
I realise this is a broad question, but I am looking for a general steer in how to tackle the problem. Code is welcome, but I am expecting to have to ask more questions as time goes on.
Thanks for the help;
Andy

Is it possible to modify the time OSCeleton sends a lost_user event/message?

I'm playing around with OSCeleton and Processing and succesfully got to track skeletons and do stuff.
What I'm wondering is if there's any way to change the delay time a "lost_user" message is sent to Processing.
This is taking so long for what I'm trying to achive, since i need to stop tracking a user as soon as he goes away from the screen, so I can accept another user's interaction. (imagine an installation where a lot of people wants to play with).
any help/tips would be really appreciated.
Jon
As far as I can tell from the OSCeleton's source and with my minimal experience with the kinect(I never used OSCeleton), there is no way to modify that code to do that. It seems to be a thing handled even lower, by the driver or by the kinect its self(?).
Yet you need not bind yourself with that, and I would suggest a couple of ways to bypass the problem if I understand properly.
First, the latest drivers and examples should have multi-user support, meaning you can just arrange who is your main user. From what I can tell from the source you do get an osc message in Processing when a new user is detected as well as an ID number. You can put each new user that arrives, into an arrayList and figure out a way to do things without depending on the latest user.
If you are still going for the user-after-user thing though, or I was mistaken about the multi-user support(which is mentioned nowhere in the README), you can check yourself whether a user has left the area. Although you can not get a definitive answer like that you can check for example, whether a specific joint or all joints of a user have moved in the last 10-20 osc messages received. That probably means storing the position of this joint in an 10-20 item array and continuously updating while also doing a check on whether the items are different. If all items in the array are the same, your user has not moved a bit and thus probably should not be taken to account.
Last but not least you can switch to other solutions. The one I used about a year ago was "Synapse for Kinect" which also seems stale now. The latest you can use is a Processing library called SimpleOpenNI which definitively have multi-user tracking and you won't need any intermediary programs running to give you the joints.
I hope this helps

User matching with current data

I have a database full of two different types of users (Mentors and Mentees), whereby I want the second group (Mentees) to be able to "search" for people in the first group (Mentors) who match their profile. Mentors and Mentees can both go in and change items in their profile at any point in time.
Currently, I am using Apache Mahout for the user matching (recommender.mostSimilarIDs()). The problem I'm running into is that I have to reload the user data every single time anyone searches. By itself, this doesn't take that long, but when Mahout processes the data it seems to take a very long time (14 minutes for 3000 Mentors and 3000 Mentees). After processing, matching takes mere seconds. I also get the same INFO message over and over again while it's processing ("Processed 2248 users"), while looking at the code shows that the message should only be outputted every 10000 users.
I'm using the GenericUserBasedRecommender and the GenericDataModel, along with the NearestNUserNeighborhood, AveragingPreferenceInferrer and PearsonCorrelationSimilarity. I load mentors from the database, add the mentee to the list of POJOs and convert them to a FastByIDMap to give to the DataModel.
Is there a better way to be doing this? The product owner needs the data to be current for every search.
(I'm the author.)
You shouldn't need to ask it to reload the data every time, why's that?
14 minutes sounds way, way too long to load such a small amount of data too, something's wrong. You might follow up with more info at user#mahout.apache.org.
You are seeing log messages from a DataModel, which you can disable in your logging system of choice. It prints one final count. This is nothing to worry about.
I would advise you against using a PreferenceInferrer unless you absolutely know you want it. Do you actually have ratings here? I might suggest LogLikelihoodSimilarity if not.

Categories