Frame to Timecode Conversion HTML5 - java

I'm looking to convert a frame number (for a given sample rate) into time in HTML5.
eg:
sample_rate = 24fps
frame 226 => ? time
Please advise.

24 fps = 1 second (your sample rate = 1 second)
226 frames / 24 fps = 9,41 seconds
total / frame_rate = time in seconds
Example:
video.currentTime = 9.41;

Related

Unexpected output of InfluxDB batch write

I am using batch processing to write into InfluxDB and below is my code for doing that.
String dbName = "test";
influxDB.query(new Query("CREATE DATABASE " + dbName, dbName));
Stopwatch watch = Stopwatch.createStarted();
influxDB.enableBatch(2000, 100, TimeUnit.MILLISECONDS);
for (int j = 0; j < 100000; j++) {
Point point = Point.measurement("cpu")
.addField("idle", (double) j)
.addField("system", 3.0 * j).build();
influxDB.write(dbName, "autogen", point);
}
influxDB.disableBatch();
System.out.println("Write for " + 100000 + " Points took:" + watch);
}
Here i am writing 100000 points and which is taking very reasonable time to write, however only few records are written into DB instead of expected 100000 records.
select count(idle) from cpu gives me only "89" i am expecting it to be "100000"
While select * from cpu gives me following:
cpu
time idle system
2016-10-06T23:57:41.184Z 8 24
2016-10-06T23:57:41.185Z 196 588
2016-10-06T23:57:41.186Z 436 1308
2016-10-06T23:57:41.187Z 660 1980
2016-10-06T23:57:41.188Z 916 2748
2016-10-06T23:57:41.189Z 1278 3834
2016-10-06T23:57:41.19Z 1405 4215
2016-10-06T23:57:41.191Z 1409 4227
2016-10-06T23:57:41.192Z 1802 5406
2016-10-06T23:57:41.193Z 1999 5997
2016-10-06T23:57:41.456Z 3757 11271
2016-10-06T23:57:41.457Z 3999 11997
2016-10-06T23:57:41.858Z 4826 14478 and so on.....
Here my question is why the values of idle are missing, for example, after 8 it should 9, 10, 11, and so on but these values were not persisted and comes directly 196 and then missing in between and then 436. Any idea how to persist all value of loop variable "j" in this situation?
This line
influxDB.enableBatch(2000, 100, TimeUnit.MILLISECONDS);
says that it will flush input data if there are more than 2000 samples per 100 ms period. Since you are trying to write 100k samples then logically most of them get flushed.
Instead, write less samples in a single batch. My recommendation would be to write 5000 samples in a single batch, and make multiple batches until all your data is in the db.
// Batch 1
influxDB.enableBatch(5000, 100, TimeUnit.MILLISECONDS);
for (int j = 0; j < 5000; j++) {
Point point = Point.measurement("cpu")
.addField("idle", (double) j)
.addField("system", 3.0 * j).build();
influxDB.write(dbName, "autogen", point);
}
influxDB.disableBatch();
// Batch 2
// ...

What is the fastest way of sending byte array down the wire using Java? And how to measure it?

What is the fastest way of sending array of 1000 bytes down the TCP Socket using Java? And how to measure it?
If my code that sends 1000 bytes arrya 25_000 times to "localhost" of the same machine would the measurement be fair?
How to achieve the fastest transfer rate?
ByteBuffer buffer = ByteBuffer.allocateDirect( 1000 );
SocketChannel clientSocketChannel = SocketChannel.open( new InetSocketAddress( "localhost", 8888 ) );
clientSocketChannel.socket().setTcpNoDelay( true );
// empty array of bytes
byte[] array = new byte[BUFFER_SIZE];
for ( int i = 0; i < 25_000; i++ ) {
buffer.put( array );
buffer.flip();
long start = System.nanoTime();
// ==========================================
do {
int len = clientSocketChannel.write( buffer );
if (len < 0)
throw new EOFException();
} while (buffer.hasRemaining());
// ==========================================
long elapsed = System.nanoTime() - start;
System.out.println( i + ":\t" + elapsed );
buffer.flip();
}
System.out.println( "Client: finished" );
I get these numbers during execution:
14669: 14543
14670: 62877
14671: 14971
14672: 13687
14673: 70576
14674: 20104
14675: 16254
14676: 60311
14677: 15826
14678: 15826
14679: 18820
14680: 13688
14681: 12832
14682: 12832
14683: 14115
14684: 12831
14685: 12832
14686: 14971
14687: 4705
14688: 4277
14689: 4278
14690: 4277
14691: 3849
14692: 4705
14693: 4706
14694: 4278
14695: 4705
14696: 4277
14697: 4277
14698: 4705
14699: 3849
14700: 4277
14701: 4277
so for 100 iterations it goes faster - then goes back to
15067: 14115
15068: 16254
15069: 19248
15070: 13687
15071: 13259
15072: 14115
15073: 14970
15074: 15827
15075: 14543
15076: 16682
15077: 14116
15078: 16254
15079: 14543
15080: 16253
iperf utility shows me that loppback can transfer 200 MBytes per second. That is approx 4 microseconds per 1000 bytes. So durign execution of my program transfer rate indeed approcahes this rate - but drops from time to time to 14-15 microseconds per 1000 bytes message. There is no JIT involved here as JIT is happening duirng first 10.000 iterations. No class loading, no garbage collection
Microbenchmarking is providing false results. If we meausre not time of each iteration but time of 1000 iterations divided by 1000 we will get more accurate results

session identification from web server log using java program

I have this kind of web log as a text file from that i want to find session from log by considering session time as 30 minutes.
1 in24.inetnebr.com 01/08/1995:00:00:01 GET /shuttle/missions/sts-68/news/sts-68-mcc-05.txt 200 1839
2 in24.inetnebr.com 01/08/1995:00:00:34 GET /shuttle/missions/sts-68/news/sts-68-mcc-06.txt 200 2303
3 in24.inetnebr.com 01/08/1995:00:05:01 GET /shuttle/missions/sts-68/news/sts-68-mcc-05.txt 200 1839
4 in24.inetnebr.com 01/08/1995:00:30:00 GET /shuttle/missions/sts-68/news/sts-68-mcc-05.txt 200 1839
5 in24.inetnebr.com 01/08/1995:00:30:55 GET /shuttle/missions/sts-68/news/sts-68-mcc-05.txt 200 1839
6 in24.inetnebr.com 01/08/1995:00:35:00 GET /shuttle/missions/sts-68/news/sts-68-mcc-05.txt 200 1839
7 slppp6.intermind.net 01/08/1995:00:00:10 GET
/history/skylab/skylab.html 200 1687
8 slppp6.intermind.net 01/08/1995:00:00:32 GET /history/skylab/skylab-1.html 200 1659
9 slppp6.intermind.net 01/08/1995:00:30:00 GET /history/skylab/skylab.html 200 1687
10 slppp6.intermind.net 01/08/1995:00:35:10 GET
/history/skylab/skylab.html 200 1687
11 133.43.96.45 01/08/1995:00:00:16 GET /shuttle/missions/sts-69/mission-sts-69.html 200 10566
12 133.43.96.45 01/08/1995:00:00:55 GET /shuttle/missions/sts-69/mission-sts-69.html 200 10566
13 133.43.96.45 01/08/1995:00:30:16 GET /shuttle/missions/sts-69/mission-sts-69.html 200 10566
14 133.43.96.45 01/08/1995:00:55:16 GET /shuttle/missions/sts-69/mission-sts-69.html 200 10566
Help me out to develop java program for finding session and what data structure i have to use.
package com.pradip.test;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class SessionIdentification {
public static void main(String[] args) throws IOException, ParseException {
Scanner s=new Scanner(new File("E:\\me_3rd\\uniqueurl.txt"));
BufferedWriter writer=new BufferedWriter(new FileWriter(new File("E:\\me_3rd\\sessions.txt")));
SimpleDateFormat format=new SimpleDateFormat("dd/mm/yyyy:HH:mm:ss");
Date d1;
Date d2;
while (s.hasNextLine()) {
String line=s.nextLine();
Scanner s1=new Scanner(new File("E:\\me_3rd\\ordertoIP.txt"));
while(s1.hasNextLine()){
Scanner s2=new Scanner(new File("E:\\me_3rd\\ordertoIP.txt"));
String line1=s1.nextLine();
String sline1[]=line1.split("");
long id=Long.parseLong(sline1[0]);
String timestamp=sline1[2];
if(line.equals(sline1[1])){
while (s2.hasNextLine()) {
String line2=s2.nextLine();
String sline2[]=line2.split(" ");
long id1=Long.parseLong(sline2[0]);
String timestamp1=sline2[2];
d1=format.parse(timestamp);
d2=format.parse(timestamp1);
long diff=d2.getTime()-d1.getTime();
long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000) % 24;
long diffDays = diff / (24 * 60 * 60 * 1000);
long seconds=(diffDays*24*60*60)+(diffHours*60*60)+(diffMinutes*60)+diffSeconds;
if(seconds<=1800){
continue ;
}
else{
String sessionboundry=id+" "+id1; //id1-1
break;
}
}
}
}
}
}
}
This is I was try but i dont know what to try next
I believe you are developing in JSF or JSP. So, You can retrieve session id from the FacesContext. you just need to append this sessionId in your log, than you can filter the result. As you required
FacesContext fCtx = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) fCtx.getExternalContext().getSession(false);
String sessionId = session.getId();
As you are interested in reading and unique logs only under 30 min session. you can read file line by line and populate your list of logs according.
A rough sketch
Format your log file properly. web / Timestamp / method / state / action / status / session id etc.
Read log file line by line in String.
Split and save logs into ArrayList if match criteria (under 30 min).

Convert Minutes to milliseconds Java/android

I am trying to convert given number of minutes into milliseconds.
For eg: 15mins or 20mins or 44mins should be converted to milliseconds programmatically.
I tried the below:
Calendar alarmCalendar = Calendar.getInstance();
alarmCalendar.set(Calendar.MINUTE,15);
long alarmTime = alarmCalendar.getTimeInMillis();
Log.e("Milli", "seconds"+alarmTime);
This doesn't give the right value? What is the best way to convert this?
TimeUnit.MINUTES.toMillis(yourMinutes)
see TimeUnit javadoc (android)
int minutes = 42;
long millis = minutes * 60 * 1000;
1 minute = 60000 millisecs.
int minutes = 1;
long milliseconds = minutes * 60000;
In Java 8+, use java.time.
java.time.Duration.ofMinutes(15).toMillis();
This answer is in reference to Android using Kotlin-
So if you are using MaterialTimePicker or TimePicker then you can get the hours and minutes values stored in the picker. Then use TimeUnit.HOURS.toMillis(picker.hour.toLong()) and TimeUnit.MINUTES.toMillis(picker.minutes.toLong()) to convert the received time to milliseconds and then add both the values to get the total time in Milliseconds which you can further use to store in Room Database for entering time and fetching when required.
Code for reference :
binding.timeStart.setOnClickListener {
openTimePicker()
picker.addOnPositiveButtonClickListener {
val h = picker.hour
val m = picker.minute
binding.timeStart.text = "$h:$m"
Timber.d("Start Time - $h: $m")
try {
val hour = TimeUnit.HOURS.toMillis(h.toLong())
val minute = TimeUnit.MINUTES.toMillis(m.toLong())
val totalTime = hour + minute
Timber.d("Hour - $hour, Minute - $minute, Total = $totalTime")
timeStart = totalTime
} catch (e: Exception) {
Timber.d("$e")
}
}
}
private fun openTimePicker() {
picker = MaterialTimePicker.Builder()
.setTimeFormat(TimeFormat.CLOCK_12H)
.setHour(12)
.setMinute(10)
.setTitleText("Set Start Time")
.build()
picker.show(childFragmentManager, "TAG")
}
This gives you the time in milli.
long currentTime = System.currentTimeMillis()
Handler handler = new Handler();
long waitTime = currentTime + (15*60*1000);
handler.postDelayed(new Runnable() {
public void run() {
// Alert or do something here.
}
}, waitTime);
This piece of code sleeps for 15 minutes and then executes the handler's run method. This way you can raise an alarm etc...

LWJGL with Slick-Util use a lot of RAM to load texture

If I use the Slick-Util to load textures into LWJGL it uses a lot of RAM. Here an example with the console-output:
Message.info ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000000 + "MB");
TextureManager.loadTexture("gui.wallpaper", "resources/wallpaper.jpg");
Message.info ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000000 + "MB");
The "TextureManager.loadTexture(...)" method is the following:
String textureFileFormat;
if (thePath.contains("png")) {
textureFileFormat = "PNG";
} else if (thePath.contains("jpg")) {
textureFileFormat = "JPG";
} else if (thePath.contains("jpeg")) {
textureFileFormat = "JPG";
} else {
textureFileFormat = "PNG";
}
theTexture = TextureLoader.getTexture(textureFileFormat, new FileInputStream(thePath), true);
// === Store it onto the HashTable === //
textures.put(theName, theTexture);
This uses (like viewable in the console output) quit 80 MB. Why? The "wallpaper.jpg" is just 290KB lage!
What is wrong?
This is the console output:
2013-09-24 21:32:40 [INFO] [CLIENT] 4MB
Tue Sep 24 21:32:40 CEST 2013 INFO:Use Java PNG Loader = true
2013-09-24 21:32:41 [INFO] [CLIENT] 89MB
I hope, that somebody of you know a solution.

Categories