Skip to content

Commit 5305f7a

Browse files
Changes for date parsing in response
1 parent b584f6c commit 5305f7a

File tree

6 files changed

+187
-10
lines changed

6 files changed

+187
-10
lines changed

DataSimulator/src/com/techolution/mauritius/data/simulator/service/BatteryDataSimiulator.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,25 @@ public void startProcess(int meterId, String startTime, String endTime, long sle
6969
}
7070

7171

72-
72+
int i = 0;
73+
long batteryVal=3200;
7374
while(startDate.before( endDate)){
7475

7576

7677
try {
7778
Telemetry telemetry=new Telemetry();
7879
telemetry.setDate(startDate);
79-
80-
telemetry.setBattery(new Long(3200));
80+
81+
if( i == 10){
82+
batteryVal = batteryVal -ThreadLocalRandom.current().nextLong(10, 30);
83+
i = 0;
84+
}
85+
86+
telemetry.setBattery(batteryVal);
87+
88+
if(batteryVal < 2000){
89+
batteryVal = 3000;
90+
}
8191

8292
telemetry.setMeter_id(meterId);
8393
sendBattery(telemetry,startDate);
@@ -94,7 +104,7 @@ public void startProcess(int meterId, String startTime, String endTime, long sle
94104
e.printStackTrace();
95105
}
96106

97-
107+
i++;
98108
}
99109

100110
}

DataSimulator/target/classes/META-INF/maven/DataSimulator/DataSimulator/pom.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Generated by Maven Integration for Eclipse
2-
#Wed Mar 21 15:16:02 IST 2018
2+
#Thu Mar 22 11:36:10 IST 2018
33
version=0.0.1-SNAPSHOT
44
groupId=DataSimulator
55
m2e.projectName=DataSimulator

DataSimulator/target/classes/META-INF/maven/DataSimulator/DataSimulator/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@
1616
<target>1.8</target>
1717
</configuration>
1818
</plugin>
19+
<plugin>
20+
<groupId>org.apache.maven.plugins</groupId>
21+
<artifactId>maven-shade-plugin</artifactId>
22+
<executions>
23+
<execution>
24+
<phase>package</phase>
25+
<goals>
26+
<goal>shade</goal>
27+
</goals>
28+
</execution>
29+
</executions>
30+
<configuration>
31+
<finalName>uber-${artifactId}-${version}</finalName>
32+
</configuration>
33+
</plugin>
1934
</plugins>
2035
</build>
2136
<dependencies>
@@ -36,4 +51,5 @@
3651
<version>20180130</version>
3752
</dependency>
3853
</dependencies>
54+
3955
</project>
332 Bytes
Binary file not shown.

connectionstatistics/src/main/java/com/techolution/mauritius/smartwater/connection/controller/ConnectionStatisticsController.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,56 @@ public class ConnectionStatisticsController {
7979
log.info("Exiting ConnectionStatisticsController.getConsumptionDetails ");
8080
return responseData;
8181
}
82+
83+
84+
/**
85+
* Taking as string as Senseworx api doesnot take json key confirming to java bean format.
86+
* If name in json and class does not match, object is not getting populated.
87+
* Hence taking as STring and creating objects manually
88+
* @param data
89+
* @return
90+
* @throws ParseException
91+
* @throws JSONException
92+
*/
93+
@PostMapping("/battery/GetData")
94+
public @ResponseBody ResponseData getBatteryDetails(@RequestBody String data) throws ParseException, JSONException
95+
96+
{
97+
log.info("Entering ConnectionStatisticsController.getBatteryDetails ");
98+
log.info("Request String is:"+data);
99+
JSONObject object=new JSONObject(data);
100+
RequestData requestData =new RequestData();
101+
requestData.setHouse_ID(object.getInt("House_ID"));
102+
requestData.setBlock_ID(object.getInt("Block_ID"));
103+
requestData.setCustomer_ID(object.getInt("Customer_ID"));
104+
requestData.setEnd_Time(object.getString("End_Time"));
105+
requestData.setStart_Time(object.getString("Start_Time"));
106+
requestData.setSample_Distance(object.getString("Sample_Distance"));
107+
requestData.setSample_Distance_value(object.getInt("Sample_Distance_value"));
108+
requestData.setVendor_ID(object.getInt("Vendor_ID"));
109+
110+
log.info("Input RequestData is not null");
111+
log.info("Input RequestData houseID:"+requestData.getHouse_ID());
112+
/*log.info("Input RequestData start time:"+requestData.getStart_Time());
113+
log.info("Input RequestData End time:"+requestData.getEnd_Time());*/
114+
115+
//Gson gsonObj = new Gson();
116+
// converts object to json string
117+
//String jsonStr = gsonObj.toJson(requestData);
118+
log.info(requestData.toString());
119+
120+
121+
122+
List<Data> resultList=connectionStatisticsService.geBatterytData(requestData);
123+
Dfj dfj=new Dfj();
124+
dfj.setStatus("Success");
125+
126+
ResponseData responseData=new ResponseData();
127+
responseData.setData(resultList);
128+
responseData.setDfj(dfj);
129+
130+
log.info("Exiting ConnectionStatisticsController.getConsumptionDetails ");
131+
return responseData;
132+
}
82133

83134
}

connectionstatistics/src/main/java/com/techolution/mauritius/smartwater/connection/service/ConnectionStatisticsService.java

Lines changed: 105 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.text.ParseException;
44
import java.text.SimpleDateFormat;
5+
import java.time.Instant;
56
import java.util.ArrayList;
67
import java.util.Calendar;
78
import java.util.Date;
@@ -80,7 +81,7 @@ else if(data.getSample_Distance().equalsIgnoreCase("Hour")){
8081

8182
int deviceId=data.getHouse_ID();
8283
//int deviceId=123;
83-
String query = "select sum(value) from flow where time >='"+startTime+"' and time<'"+endTime+"' and meter_id="+deviceId+" group by time("+groupVal+") fill(0)";// now() - 10d and meter_id = '124' group by time(1d) fill(0)
84+
String query = "select sum(value) from flow where time >='"+startTime+"' and time<='"+endTime+"' and meter_id="+deviceId+" group by time("+groupVal+") fill(0)";// now() - 10d and meter_id = '124' group by time(1d) fill(0)
8485
log.debug("Query is:"+query);
8586

8687

@@ -93,10 +94,12 @@ else if(data.getSample_Distance().equalsIgnoreCase("Hour")){
9394
List<Result> resultlist=queryResult.getResults();
9495
int recordSize=0;
9596
List<Data> retlist=new ArrayList<Data>();
96-
SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
97-
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
97+
//SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
98+
//SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-ddTHH:mm:ssZ");
99+
//dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
98100
//Date date1=new SimpleDateFormat("yyyy-MM-DDTHH:mm:ssz").parse(sDate1);
99101
Data resultData=null;
102+
Instant instant=null;
100103
for(Result result:resultlist){
101104
List<Series> serieslist=result.getSeries();
102105
if(serieslist == null){
@@ -106,8 +109,10 @@ else if(data.getSample_Distance().equalsIgnoreCase("Hour")){
106109
List<List<Object>> valuelist=series.getValues();
107110
for(List<Object> results:valuelist){
108111
String endTimeReturned=(String)results.get(0);
109-
log.debug("Date is:"+(endTimeReturned.split("T"))[0]);
110-
Date date=dateFormat.parse(endTimeReturned);
112+
/*log.debug("Date is:"+(endTimeReturned.split("T"))[0]);
113+
log.debug("Date2 is:"+(endTimeReturned.split("T"))[1]);*/
114+
instant= Instant.parse( endTimeReturned);
115+
Date date=java.util.Date.from(instant);
111116

112117
resultData=new Data();
113118
resultData.setDevid(deviceId);
@@ -125,6 +130,101 @@ else if(data.getSample_Distance().equalsIgnoreCase("Hour")){
125130
return retlist;
126131
}
127132

133+
public List<Data> geBatterytData(RequestData data) throws ParseException{
134+
135+
136+
SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
137+
138+
139+
/*String startTime = myFormat.format(data.getStart_Time().getTime());
140+
String endTime = myFormat.format(data.getEnd_Time().getTime());*/
141+
String startTime = data.getStart_Time();
142+
//String startTime = "2018-03-01";
143+
144+
String endTime = data.getEnd_Time();
145+
//String endTime = "2018-03-15";
146+
147+
int distanceValue=data.getSample_Distance_value();
148+
//int distanceValue=30;
149+
String disVal=String.valueOf(distanceValue);
150+
151+
String code="d";
152+
String groupVal=null;
153+
log.debug("Sample Distance:"+data.getSample_Distance());
154+
log.debug("distanceValue:"+distanceValue);
155+
//String groupVal="1d";
156+
if(data.getSample_Distance().equalsIgnoreCase("Day")){
157+
code="d";
158+
groupVal=disVal+code;
159+
}
160+
else if(data.getSample_Distance().equalsIgnoreCase("Hour")){
161+
code="h";
162+
groupVal=disVal+code;
163+
}else if(data.getSample_Distance().equalsIgnoreCase("Month")){
164+
int monthgroupval=distanceValue*30;
165+
groupVal=String.valueOf(monthgroupval)+"d";
166+
167+
}else{
168+
code="d";
169+
groupVal=disVal+code;
170+
}
171+
172+
173+
int deviceId=data.getHouse_ID();
174+
//int deviceId=123;
175+
String query = "select last(value) from batterylevel where time >='"+startTime+"' and time<='"+endTime+"' and meter_id="+deviceId+" group by time("+groupVal+")";// now() - 10d and meter_id = '124' group by time(1d) fill(0)
176+
log.debug("Query is:"+query);
177+
178+
179+
//InfluxDB influxDB = InfluxDBFactory.connect("http://localhost:32770", "root", "root");
180+
InfluxDB influxDB = InfluxDBFactory.connect(INFLUX_CONNECTION_STRING, INFLUX_USERNAME, INFLUX_PWD);
181+
String dbName = "mauritius_smartwater";
182+
QueryResult queryResult = influxDB.query(new Query(query, dbName));
183+
String locationName= "TEST";
184+
185+
List<Result> resultlist=queryResult.getResults();
186+
// int recordSize=0;
187+
List<Data> retlist=new ArrayList<Data>();
188+
//SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
189+
//dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
190+
//Date date1=new SimpleDateFormat("yyyy-MM-DDTHH:mm:ssz").parse(sDate1);
191+
Data resultData=null;
192+
193+
Instant instant=null;
194+
for(Result result:resultlist){
195+
List<Series> serieslist=result.getSeries();
196+
if(serieslist == null){
197+
break;
198+
}
199+
for(Series series:serieslist){
200+
List<List<Object>> valuelist=series.getValues();
201+
for(List<Object> results:valuelist){
202+
String endTimeReturned=(String)results.get(0);
203+
//log.debug("Date is:"+(endTimeReturned.split("T"))[0]);
204+
instant= Instant.parse( endTimeReturned);
205+
Date date=java.util.Date.from(instant);
206+
// Date date=dateFormat.parse(endTimeReturned);
207+
if(results.get(1)!=null){
208+
209+
210+
resultData=new Data();
211+
resultData.setDevid(deviceId);
212+
resultData.setEndtime(date);
213+
214+
resultData.setWdata(((Double)results.get(1)).doubleValue());
215+
resultData.setSensor_locationname(locationName);
216+
retlist.add(resultData);
217+
}
218+
}
219+
220+
221+
}
222+
223+
}
224+
influxDB.close();
225+
return retlist;
226+
}
227+
128228
/**
129229
*
130230
* @param telemetry

0 commit comments

Comments
 (0)