Skip to content

Commit 83ea2d7

Browse files
Changes to give extra details for leakage service and location as part of baseline
1 parent 1ff5df8 commit 83ea2d7

File tree

3 files changed

+181
-10
lines changed

3 files changed

+181
-10
lines changed

supplydataservice/src/main/java/com/techolution/mauritius/smartwater/supply/controller/LeakageDataController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class LeakageDataController {
3838
public @ResponseBody List<ConsumptionLeakage> getDailyConsumerLeakageStats()
3939
{
4040
log.info("Entering LeakageDataController.getDailyConsumerLeakageStats");
41-
List<ConsumptionLeakage> resultList=analyticService.getCurrentDayConsumerLeakage();
41+
List<ConsumptionLeakage> resultList=analyticService.getCurrentDayConsumerLeakageDetails();
4242
log.info("Exiting LeakageDataController.getDailyConsumerLeakageStats");
4343
return resultList;
4444
}

supplydataservice/src/main/java/com/techolution/mauritius/smartwater/supply/domain/ConsumptionLeakage.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,31 @@ public class ConsumptionLeakage implements Serializable {
1111
private static final long serialVersionUID = 1L;
1212
private String meterId;
1313
private Date date;
14-
private double leakage;
14+
private double leakageVolume;
15+
private String location;
16+
private String startTime;
17+
private String endTime;
1518

19+
20+
21+
public String getLocation() {
22+
return location;
23+
}
24+
public void setLocation(String location) {
25+
this.location = location;
26+
}
27+
public String getStartTime() {
28+
return startTime;
29+
}
30+
public void setStartTime(String startTime) {
31+
this.startTime = startTime;
32+
}
33+
public String getEndTime() {
34+
return endTime;
35+
}
36+
public void setEndTime(String endTime) {
37+
this.endTime = endTime;
38+
}
1639
public String getMeterId() {
1740
return meterId;
1841
}
@@ -25,11 +48,12 @@ public Date getDate() {
2548
public void setDate(Date date) {
2649
this.date = date;
2750
}
28-
public double getLeakage() {
29-
return leakage;
51+
public double getLeakageVolume() {
52+
return leakageVolume;
3053
}
31-
public void setLeakage(double leakage) {
32-
this.leakage = leakage;
54+
public void setLeakageVolume(double leakageVolume) {
55+
this.leakageVolume = leakageVolume;
3356
}
57+
3458

3559
}

supplydataservice/src/main/java/com/techolution/mauritius/smartwater/supply/service/SupplyAnalyticsService.java

Lines changed: 151 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.techolution.mauritius.smartwater.supply.service;
22

3-
import java.sql.Date;
3+
44
import java.text.SimpleDateFormat;
55
import java.time.Instant;
66
import java.util.ArrayList;
77
import java.util.Calendar;
8+
import java.util.Collection;
9+
import java.util.Date;
10+
import java.util.HashMap;
811
import java.util.List;
912
import java.util.Map;
1013
import java.util.TimeZone;
@@ -23,6 +26,7 @@
2326

2427
import com.techolution.mauritius.smartwater.supply.InfluxProperties;
2528
import com.techolution.mauritius.smartwater.supply.domain.ConsumptionLeakage;
29+
import com.techolution.mauritius.smartwater.supply.domain.DailyWaterSupplyData;
2630
import com.techolution.mauritius.smartwater.supply.domain.LeakageData;
2731
import com.techolution.mauritius.smartwater.supply.domain.MeterConnection;
2832
import com.techolution.mauritius.smartwater.supply.domain.MeterTrendData;
@@ -58,6 +62,8 @@ public class SupplyAnalyticsService {
5862

5963
private static String SERIES_NAME_CONSUMERLEAKAGE="consumerleakage";
6064
private static String SERIES_NAME_NETWORKLEAKAGE="networkleakage";
65+
private static String SERIES_NAME_CONSUMERLEAKAGE_ON="consumerleakageontime";
66+
private static String SERIES_NAME_CONSUMERLEAKAGE_OFF="consumerleakageofftime";
6167

6268

6369

@@ -104,6 +110,16 @@ public List<MeterTrendData> getConnectionsAboveDailyBaseline(){
104110

105111
}
106112

113+
Map <Long, MeterConnection> connMap=getConnectionsMap();
114+
115+
retList.forEach(trendData -> {
116+
117+
MeterConnection connection=connMap.get(new Long(trendData.getMeterId()));
118+
if(connection!=null){
119+
trendData.setLocation(connection.getHouse_namenum());
120+
}
121+
});
122+
107123

108124
log.info("Existing SupplyAnalyticsService.getConnectionsAboveDailyBaseline");
109125
return retList;
@@ -170,6 +186,15 @@ public List<MeterTrendData> getConnectionsBelowDailyBaseline(){
170186

171187
}
172188

189+
Map <Long, MeterConnection> connMap=getConnectionsMap();
190+
191+
retList.forEach(trendData -> {
192+
193+
MeterConnection connection=connMap.get(new Long(trendData.getMeterId()));
194+
if(connection!=null){
195+
trendData.setLocation(connection.getHouse_namenum());
196+
}
197+
});
173198

174199
log.info("Existing SupplyAnalyticsService.getConnectionsBelowDailyBaseline");
175200
return retList;
@@ -458,7 +483,7 @@ public LeakageData getCurrentDayLeakageData(){
458483
});
459484
}
460485

461-
486+
influxDB.close();
462487
log.info("Exiting SupplyAnalyticsService.getStats");
463488
return leakageData;
464489

@@ -504,7 +529,7 @@ public List<ConsumptionLeakage> getCurrentDayConsumerLeakage(){
504529
List<List<Object>> values=series.getValues();
505530
if(values !=null && values.size()>0){
506531
List<Object> value=values.get(0);
507-
leakage.setLeakage( (Double)value.get(1));
532+
leakage.setLeakageVolume( (Double)value.get(1));
508533

509534
String time=(String)value.get(0);
510535
Instant instant=Instant.parse(time);
@@ -516,11 +541,133 @@ public List<ConsumptionLeakage> getCurrentDayConsumerLeakage(){
516541

517542
});
518543
}
519-
544+
influxDB.close();
520545

521546
log.info("Exiting SupplyAnalyticsService.getCurrentDayConsumerLeakage");
522547
return resultList;
523548

549+
}
550+
551+
public List<ConsumptionLeakage> getCurrentDayConsumerLeakageDetails(){
552+
553+
log.info("Entering SupplyAnalyticsService.getCurrentDayConsumerLeakageDetails");
554+
555+
// SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
556+
List<ConsumptionLeakage> outputlist= new ArrayList<ConsumptionLeakage>();
557+
558+
//TODO Add date specific filtering again
559+
/*String startTime=myFormat.format(data.getStartDate());
560+
String endTime=myFormat.format(data.getEndDate());
561+
Calendar currentCal=Calendar.getInstance();
562+
Date currentTime=currentCal.getTime();
563+
if(data.getEndDate().after(currentTime)){
564+
565+
currentCal.add(Calendar.DATE, -1);
566+
endTime=myFormat.format(currentCal.getTime());
567+
}*/
568+
569+
// String query = "select time,value from "+SERIES_NAME_CONSUMERLEAKAGE_ON+" , "+SERIES_NAME_CONSUMERLEAKAGE_OFF+ " where meter_id='"+data.getMeterId()+"' and time >= '"+startTime+"' and time <='"+endTime+"' order by time asc";
570+
String query = "select * from "+SERIES_NAME_CONSUMERLEAKAGE_ON+" , "+SERIES_NAME_CONSUMERLEAKAGE_OFF+" order by time asc";
571+
572+
573+
SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
574+
dateFormat.setTimeZone(TimeZone.getTimeZone(influxProperties.getDatatimezone()));
575+
InfluxDB influxDB = InfluxDBFactory.connect(influxProperties.getUrl(),influxProperties.getUsername(),influxProperties.getPassword());
576+
long startStarttime=System.currentTimeMillis();
577+
QueryResult queryResult = influxDB.query(new Query(query, influxProperties.getDbname()));
578+
long endtime=System.currentTimeMillis();
579+
log.debug("Time After getCurrentDayConsumerLeakageDetails query execution:"+endtime);
580+
log.debug("Time Taken for getCurrentDayConsumerLeakageDetails query execution:"+(endtime-startStarttime));
581+
log.debug("Query is:"+query);
582+
583+
List<Result> resultlist=queryResult.getResults();
584+
585+
Map<String,ConsumptionLeakage> outputmap=new HashMap<String,ConsumptionLeakage>();
586+
if(resultlist != null && resultlist.size()>0){
587+
588+
Result result=resultlist.get(0);
589+
List<Series> serieslist=result.getSeries();
590+
serieslist.forEach(series -> {
591+
592+
String name=series.getName();
593+
594+
List<List<Object>> valuelist=series.getValues();
595+
valuelist.parallelStream().forEach( values -> {
596+
597+
String timestamp=(String)values.get(0);
598+
String meter_id=(String)values.get(1);
599+
600+
Instant instant=Instant.parse(timestamp);
601+
Date dt=Date.from(instant);
602+
603+
604+
605+
ConsumptionLeakage leakageData=outputmap.get(meter_id);
606+
if(leakageData == null){
607+
leakageData =new ConsumptionLeakage();
608+
}
609+
leakageData.setMeterId(meter_id);
610+
611+
if(SERIES_NAME_CONSUMERLEAKAGE_ON.equalsIgnoreCase(name)){
612+
leakageData.setStartTime(dateFormat.format(dt));
613+
}else{
614+
leakageData.setEndTime(dateFormat.format(dt));
615+
}
616+
617+
outputmap.put(meter_id, leakageData);
618+
619+
620+
});
621+
});
622+
623+
}
624+
625+
626+
//TODO Add time base filter. It also assumes that data will be here whenever data is there in consumerleakageontime and consumerleakageofftime
627+
String leakagevalquery="select sum(value) from consumerleakage group by meter_id ";
628+
long leakagevalqueryresultStarttime=System.currentTimeMillis();
629+
QueryResult leakagevalqueryresult = influxDB.query(new Query(leakagevalquery, influxProperties.getDbname()));
630+
long leakagevalqueryresultendtime=System.currentTimeMillis();
631+
log.debug("Time Taken for leakagevalquery query execution:"+(leakagevalqueryresultendtime-leakagevalqueryresultStarttime));
632+
List<Result> leakageValResult=leakagevalqueryresult.getResults();
633+
if(leakageValResult != null && leakageValResult.size()>0){
634+
Result result=leakageValResult.get(0);
635+
636+
List<Series> serieslist=result.getSeries();
637+
638+
serieslist.forEach(series -> {
639+
String meterId=series.getTags().get("meter_id");
640+
641+
List<List<Object>> valuelist=series.getValues();
642+
if(valuelist !=null && valuelist.size()>0){
643+
List<Object> value=valuelist.get(0);
644+
ConsumptionLeakage leakage=outputmap.get(meterId);
645+
leakage.setLeakageVolume((Double)value.get(1));
646+
}
647+
648+
});
649+
}
650+
651+
652+
/*Collection<DailyWaterSupplyData> ouput=outputmap.values();
653+
List<DailyWaterSupplyData> outputlist=new ArrayList<DailyWaterSupplyData>();
654+
outputlist.addAll(ouput);*/
655+
656+
Map <Long, MeterConnection> connmap=getConnectionsMap();
657+
Collection<ConsumptionLeakage> ouput=outputmap.values();
658+
outputlist.addAll(ouput);
659+
outputlist.forEach(consumptionleakage -> {
660+
Long meterId=new Long(consumptionleakage.getMeterId());
661+
MeterConnection meterconn= connmap.get(meterId);
662+
if(meterconn!=null){
663+
consumptionleakage.setLocation(meterconn.getHouse_namenum());
664+
}
665+
});
666+
667+
influxDB.close();
668+
log.info("Exiting SupplyAnalyticsService.getCurrentDayConsumerLeakageDetails");
669+
return outputlist;
670+
524671
}
525672

526673
}

0 commit comments

Comments
 (0)