Say i get a value that is a difference of current time in milliseconds - some datetime in milliseconds.
double value = Calendar.getInstance().getTimeInMillis() - getMilliseconds(reportingDt);
So this would be a quite a big value. Now i want to normalize it to a scale of 0 - 1.
Please can some one suggest how can this be achieved in java, so that my value is scaled in between 0 and 1.
The more recent is the reportingDt more the final value is towards 1 and older the reportingDt more it is towards 0.
UPDATE
Well my approach towards normalizing it was as below. This is more of a prototype, but it worked for me.
private double getDocumentScore(String reportingDt) {
Date offset = null;
try {
offset = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS").parse("24-08-2017 13:53:30.802");
} catch (ParseException e) {
e.printStackTrace();
}
long currentTime = Calendar.getInstance().getTimeInMillis();
if(offset != null) {
// If offset is set then instead of current datetime consider offset
currentTime = offset.getTime();
}
System.out.println(reportingDt);
long value = currentTime - getMilliseconds(reportingDt);
long minutes = TimeUnit.MILLISECONDS.toMinutes(value);
double score = 2 * (1 / Math.log(minutes));
System.out.println(score);
return score;
}
private long getMilliseconds(String dateTime) {
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS");
Date date = null;
try {
date = formatter.parse(dateTime);
} catch (ParseException e) {
e.printStackTrace();
}
return date.getTime();
}
Sample input date and output normalized score values were
11-07-2017 14:34:05.416
0.18089822028334113
11-07-2017 14:34:06.023
0.18089822028334113
11-07-2017 14:34:06.595
0.18089822028334113
11-07-2017 14:34:07.139
0.18089822028334113
11-07-2017 14:34:08.873
0.18089822028334113
11-07-2017 14:34:11.171
0.18089822028334113
11-07-2017 14:34:12.954
0.18089822028334113
11-07-2017 14:34:12.962
0.18089822028334113
11-07-2017 14:34:34.516
0.18089847869291217
11-07-2017 14:34:35.720
0.18089847869291217
11-07-2017 14:34:38.566
0.18089847869291217
11-07-2017 14:34:39.205
0.18089847869291217
11-07-2017 14:34:40.357
0.18089847869291217
Below is the graph plot for various score function i considered to normalize the value. Finally i used green line one (2* (1/log(x)))
Do like this-