-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSampleDataGenerator
More file actions
33 lines (26 loc) · 1.02 KB
/
SampleDataGenerator
File metadata and controls
33 lines (26 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.example.demo;
import java.util.LinkedList;
import org.springframework.beans.factory.annotation.Autowired;
public class RandomGenerator {
@Autowired
private WeatherDataRepository weatherRepository;
private LinkedList<WeatherDataPOJO> listWeatherData = new LinkedList<WeatherDataPOJO>();
public void generateWeatherData() {
for(int i = 0; i < 100; i ++) {
Long nextTimeStamp = (long) (i * 5 * 60 * 1000);
for(int j=0; j< 10000;j++) {
WeatherDataPOJO WDP = new WeatherDataPOJO();
WDP.setSensorID((int)j%10000);
WDP.setTemperature((int) getRandomIntegerBetweenRange(2,55));
WDP.setTemperature((int) getRandomIntegerBetweenRange(2,55));
WDP.setTimeStamp(System.currentTimeMillis()/1000+(int) getRandomIntegerBetweenRange(0,300000) + nextTimeStamp);
listWeatherData.add(WDP);
}
}
weatherRepository.saveAll(listWeatherData);
}
public static double getRandomIntegerBetweenRange(double min, double max){
double x = (int)(Math.random()*((max-min)+1))+min;
return x;
}
}