Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Hi i make service
that is get data from postgreDatabase
is doing loop when data End
so yesterday it was done
but today when i execute service
come err
so i try find this err in this community
but i can't find
could you help me plz?
thanks
Solved! Go to Solution.
Hi Seonho Cha,
The error message you saw here may be a little misleading. To check exactly what's the issue, you could try to enable stack trace.
will contain the underlying reason for the error.
After stack trace enabled, you could also attach the ThingWorx error log file here.
Thanks,
Br,
Anna
Hi Seonho Cha,
Could you attach your code here too?
If possible, please also provide your postgreSQL database connection configuration in ThingWorx(I suppose thePostgreSQL database you mentioned is as an external db not the persistence provider here, correct?)
Thanks,
Br,
Anna
Dear Anna An
My code is so dirty...
but i attach mt code
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if(Things["GetTruckDateFromPostgreDB"].isConnected){
var result = Things["GetTruckDateFromPostgreDB"].GetTruckDataFirstTime({cdma_number: me.vehicle_ID});
var L = result.getRowCount();
var P=0;//상
var PP=0;//하
var T=0;//만
var TT=0;//공
var D=0;//만
var DD=0;//공
var LC=0;
var TC = 0;
var TCC = 0;
var R = 0;
var PW=0;
var PWC=0;
var CW=0;
var testStr;
var status;
var weightresult;
for(var i=0;i < L;i++){
var AX1 = result.getRow(i);
var speed = AX1.speed;
var W = result.getRow(i).weight_total;
var weight_axle = AX1.weight_axle;
var Time = result.getRow(i).kst_datetime;
var params = {
datetime: result.getRow(i).kst_datetime /* DATETIME */,
cdma_number: me.vehicle_ID /* STRING */
};
// result: INFOTABLE dataShape: TruckDataFeildDataShape
var Truck2 = Things["GetTruckDateFromPostgreDB"].CompareTruckData(params);
var W2 = Truck2.weight_total;
var Time2 = Truck2.kst_datetime;
if(AX1.a1 > 20000|| AX1.a2 > 20000|| AX1.a3 > 20000|| AX1.a4 > 20000|| AX1.a5 > 20000|| AX1.a6 > 20000|| AX1.a7 > 20000){
for(var k=0;k<Truck2.getRowCount();k++){
var AX11 = Truck2.getRow(k);
if(AX11.a1 < 20000&& AX11.a2 < 20000&& AX11.a3 < 20000&& AX11.a4 < 20000&& AX11.a5 < 20000&& AX11.a6 < 20000&& AX11.a7 < 20000){
W=AX11.weight_total;
}
}
}
if(Truck2.a1 >20000 || Truck2.a2 >20000 || Truck2.a3 >20000 || Truck2.a4 >20000 || Truck2.a5 >20000 || Truck2.a6 >20000 || Truck2.a7 >20000){
for(var j=0;j<Truck2.getRowCount();j++){
var AX = Truck2.getRow(j);
if(AX.a1 <20000 && AX.a2 <20000 && AX.a3 <20000 && AX.a4 <20000 && AX.a5 <20000 && AX.a6 <20000 && AX.a7 <20000){
W2 = AX.weight_total;
break;
}
}
}
var PGPS = new Object();
var GPS = new Object();
GPS.latitude = parseInt(AX1.latitude/100)+(AX1.latitude - parseInt(AX1.latitude/100)*100)/60;
GPS.longitude= parseInt(AX1.longitude/100)+(AX1.longitude - parseInt(AX1.longitude/100)*100)/60;
GPS.elevation = 0;
GPS.units = "WGS84";
if(Truck2.latitude == 0){
for(var m=0;m<Truck2.getRowCount();m++){
var MX = Truck2.getRow(m);
if(MX.latitude != 0){
PGPS.latitude = parseInt(MX.latitude/100)+(MX.latitude - parseInt(MX.latitude/100)*100)/60;
PGPS.longitude= parseInt(MX.longitude/100)+(MX.longitude - parseInt(MX.longitude/100)*100)/60;
PGPS.elevation = 0;
PGPS.units = "WGS84";
break;}}
}else{
PGPS.latitude = parseInt(Truck2.latitude/100)+(Truck2.latitude - parseInt(Truck2.latitude/100)*100)/60;
PGPS.longitude= parseInt(Truck2.longitude/100)+(Truck2.longitude - parseInt(Truck2.longitude/100)*100)/60;
PGPS.elevation = 0;
PGPS.units = "WGS84";
}
if(AX1.latitude==0){
GPS=PGPS;
}
// distanceBetween(loc1:LOCATION,loc2:LOCATION,units:STRING):NUMBER
var DDiff = distanceBetween(GPS, PGPS, "");
DDiff = DDiff* 1.60934;
var Tdiff = (Time - Time2)/1000
if(Tdiff>1200){
Tdiff=60;}
if(W>me.weight_threshold){
weightresult="만차";
status="운송";
T+=Tdiff;
D+=DDiff;
}
else{
weightresult="공차";
status="이동";
TT+=Tdiff;
DD+=DDiff;
}
if(W>me.weight_threshold && W2<me.weight_threshold){
P+=1;
PW=0;
PWC=1;
me.PW = true;
var params = {
lat: GPS.latitude /* STRING */,
long: GPS.longitude /* STRING */
};
// result: STRING
var address = Things["GetAddressThing"].GetAddress(params);
var values = Things["TruckPickEventsInfoStream"].CreateValues();
values.PickUpGPS = GPS; //LOCATION
values.PickUpLoc = address; //STRING
values.PickUpT = Time.getHours()+"시 "+Time.getMinutes()+"분"; //STRING
var params = {
sourceType: undefined /* STRING */,
values: values /* INFOTABLE*/,
location: GPS /* LOCATION */,
source: me.name /* STRING */,
timestamp: Time /* DATETIME */,
tags: undefined /* TAGS */
};
// no return
Things["TruckPickEventsInfoStream"].AddStreamEntry(params);
var SD = Things["TruckPickEventLocateStream"].QueryStreamEntriesWithData({source: me.name});
if(SD.getRowCount()==0){
var values = Things["TruckPickEventLocateStream"].CreateValues();
values.time_pickevent = Time; //DATETIME
values.locate_pickevent = GPS; //LOCATION
values.envet_name = "상차"; //STRING
var params = {
tags : undefined,
timestamp : Time,
source : me.name,
values : values,
location : GPS
};
Things["TruckPickEventLocateStream"].AddStreamEntry(params);}
else{
for(var lm=0;lm<SD.getRowCount();lm++){
var LGPS = SD.getRow(lm).locate_pickevent;
var LDiff = distanceBetween(GPS, LGPS, "");
LDiff = LDiff * 1.60934;
if(LDiff > 1){
LC = 1;
continue;
}
else if(LDiff < 1){
LC = 0;
//lm = SD.getRowCount();
break;
}
}
if(LC==1){
var values = Things["TruckPickEventLocateStream"].CreateValues();
values.time_pickevent = Time; //DATETIME
values.locate_pickevent = GPS; //LOCATION
values.envet_name = "상차"; //STRING
var params = {
tags : undefined,
timestamp : Time,
source : me.name,
values : values,
location : GPS
};
Things["TruckPickEventLocateStream"].AddStreamEntry(params);}
}
}
if(W<me.weight_threshold && W2>me.weight_threshold){
PP+=1;
PWC=-1;
var params = {
lat: GPS.latitude /* STRING */,
long: GPS.longitude /* STRING */
};
// result: STRING
var address = Things["GetAddressThing"].GetAddress(params);
var query =
{
"filters": {
"type": "LT",
"fieldName": "timestamp",
"value": Time
}
};
var params = {
oldestFirst: undefined /* BOOLEAN */,
maxItems: undefined /* NUMBER */,
sourceTags: undefined /* TAGS */,
endDate: undefined /* DATETIME */,
query: query /* QUERY */,
source: me.name /* STRING */,
startDate: undefined /* DATETIME */,
tags: undefined /* TAGS */
};
// result: INFOTABLE
var EEE = Things["TruckPickEventsInfoStream"].QueryStreamEntriesWithData(params);
var values = Things["TruckPickEventsInfoStream"].CreateValues();
values.PickDownLoc = address; //STRING
values.PickDownT = Time.getHours()+"시 "+Time.getMinutes()+"분";; //STRING
values.PickUpT = EEE.PickUpT;
values.PickDownGPS = GPS; //LOCATION
values.PickUpLoc = EEE.PickUpLoc;
values.PickUpGPS = EEE.PickUpGPS;
var params = {
values: values /* INFOTABLE*/,
streamEntryId: EEE.id /* STRING */,
location: undefined /* LOCATION */,
source: me.name /* STRING */,
tags: undefined /* TAGS */
};
// no return
Things["TruckPickEventsInfoStream"].UpdateStreamEntry(params);
var SD = Things["TruckPickEventLocateStream"].QueryStreamEntriesWithData({source: me.name});
if(SD.getRowCount()==0){
var values = Things["TruckPickEventLocateStream"].CreateValues();
values.time_pickevent = Time; //DATETIME
values.locate_pickevent = GPS; //LOCATION
values.envet_name = "하차"; //STRING
var params = {
tags : undefined,
timestamp : Time,
source : me.name,
values : values,
location : GPS
};
Things["TruckPickEventLocateStream"].AddStreamEntry(params);}
else{
for(var lm=0;lm<SD.getRowCount();lm++){
var LGPS = SD.getRow(lm).locate_pickevent;
var LDiff = distanceBetween(GPS, LGPS, "");
LDiff = LDiff * 1.60934;
if(LDiff > 1){
LC = 1;
continue;
}
else if(LDiff < 1){
LC = 0;
//lm = SD.getRowCount();
break;
}
}
if(LC == 1){
var values = Things["TruckPickEventLocateStream"].CreateValues();
values.time_pickevent = Time; //DATETIME
values.locate_pickevent = GPS; //LOCATION
values.envet_name = "하차"; //STRING
var params = {
tags : undefined,
timestamp : Time,
source : me.name,
values : values,
location : GPS
};
Things["TruckPickEventLocateStream"].AddStreamEntry(params);}
}
}
if(speed<=20 && TCC==0){
TC = parseInt(Time.getHours() * 60) + Time.getMinutes();
if(speed<5){
TCC=1;}
}
else if(speed > 20){
TCC=0
}
var Mandoo =(parseInt(Time.getHours()*60) +Time.getMinutes()) - TC;
if(Mandoo > 6 && TCC==1){
status="정차";
if(Mandoo > 30 && TCC==1){
R+=1;
TCC=3;
}
}
if(PWC==1 && speed>20){
PW+=W;
PWC=2;
CW=CW;
}
else if(PWC==2){
PW+=W;
CW=CW;
PWC=3;}
else if(PWC==3){
PW = (PW+W)/3;
CW +=PW;
testStr += CW+"ㅁ"+PW+"ㄴnn";
PWC=4;
me.PW=false;}
else if(PWC>3){
PWC+=1;
}
}
//처음 만들때 만들어지는 순간까지의 상하차지 정보및 상하차 횟수 운행 이동 거리 를 구해서 뿌린다.
me.StartTime = result.kst_datetime;
me.RecieveTime = Time;
me.RecieveCount = result.getRowCount();
me.pickup=P;
me.pickuptotal=P;
me.pickdown=PP;
me.pickdowntotal=PP;
if(!me.PW && PWC>4){
me.pick_weight=PW;
me.PWC=777;
}else{
me.PWC=1;
me.pick_weight=0;
}
me.comulative_weight=CW;
me.drive_time_total=TT+T;
me.move_distance_total=DD;
me.move_time_total=TT;
me.transit_distance_total=D;
me.transit_time_total=T;
me.drive_distance=DD+D;
me.move_distance=DD;
me.transit_distance=D;
me.drvie_time=T+TT;
me.transit_time=T;
me.move_time=TT;
var params = {
infoTableName : "UpdatePropertiesInfoTableTMP",
dataShapeName : "NamedVTQ"
};
// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(NamedVTQ)
var Update = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
Update.AddRow({'time':Time,'name':'speed','value':speed,'quallity':undefined});
Update.AddRow({'time':Time,'name':'weight','value':W,'quallity':undefined});
Update.AddRow({'time':Time,'name':'weight_axle','value':weight_axle,'quallity':undefined});
Update.AddRow({'time':Time,'name':'status','value':status,'quallity':undefined});
Update.AddRow({'time':Time,'name':'weight_result','value':weightresult,'quallity':undefined});
Update.AddRow({'time':Time,'name':'GPS','value':GPS,'quallity':undefined});
Update.AddRow({'time':Time,'name':'rest','value':R,'quallity':undefined});
//View1,2는 각각 이동 운송시간보여줄것들
var trs_dst = me.transit_distance.toFixed(2)+"Km";
var mv_dst = me.move_distance.toFixed(2)+"Km";
Update.AddRow({'time':Time,'name':'View1','value':trs_dst,'quallity':undefined});
Update.AddRow({'time':Time,'name':'View2','value':mv_dst,'quallity':undefined});
var tr_t = parseInt(me.transit_time/3600)+"시간 "+parseInt((me.transit_time/60) % 60)+"분";
var mv_t = parseInt(me.move_time/3600)+"시간 "+parseInt((me.move_time / 60)%60)+"분";
Update.AddRow({'time':Time,'name':'View3','value':tr_t,'quallity':undefined});
Update.AddRow({'time':Time,'name':'View4','value':mv_t,'quallity':undefined});
var params = {
lat: GPS.latitude /* STRING */,
long: GPS.longitude /* STRING */
};
// result: STRING
var address = Things["GetAddressThing"].GetAddress(params);
Update.AddRow({'time':Time,'name':'GPS_address','value':address,'quallity':undefined});
me.UpdatePropertyValues({values:Update});
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
and my configuration
thanks
Hi Seonho Cha,
Indeed the code is so long and it contains many other logics besides the database query.
Could you please split your functions and just create another service for the postgreSQL query part? see if it work or not and you could attach that part of code here if you like.
Thanks,
Br,
Anna
Those codes are simply code that gets the values from the database. Otherwise, it is an algorithm to obtain the current state of the vehicle.
Hi Seonho Cha,
Which service in your code is refering external db query? is it
GetTruckDataFirstTime() or CompareTruckData()?
and, could you try to add some debugging log print to check where you got this issue in your code?
For example, add logger.warn(x) before and after the code section:
me.UpdatePropertyValues({values:Update});
to make sure me.UpdatePropertyValues({values:Update}) is executed or not. Do the same for other places that you suspect relevant to your issue.
Thanks,
Br,
Anna
Hi Seonho Cha,
The error message you saw here may be a little misleading. To check exactly what's the issue, you could try to enable stack trace.
will contain the underlying reason for the error.
After stack trace enabled, you could also attach the ThingWorx error log file here.
Thanks,
Br,
Anna
Dear Anna An
I was late to work on other tasks. I will use your advice to resolve this issue. Thank you for your attention.