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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
| int linesize = 0;
main() { startThread("initTrend"); delay(0.5); startThread("showAlert"); }
void initTrend() { file fileHandle = fopen("D://test1.txt", "r+");
string line = ""; dyn_string lines; while(!feof(fileHandle)) { fgets(line, 100, fileHandle); dyn_string str = strsplit(line, "\n"); if(dynlen(str) > 0) line = str[1]; int len = strlen(line); while(len > 0 && line[len - 1] == " ") len -- ; line = substr(line, 0, len); lines.append(line); } fclose(fileHandle);
string trendName; int trendCount; for(int i = 1; i <= dynlen(lines); i ++ ) { if(lines[i] == "") { } else if(strpos(lines[i], "trendName", 0) > 0) { i ++ ; trendName = lines[i]; } else if(strpos(lines[i], "curveCount", 0) > 0) { i ++ ; trendCount = (int)lines[i]; for(int j = 1; j <= trendCount; j ++ ) { if(j != 1) setValue(trendName, "curveScaleVisibility", "curve" + j, false); if(j < trendCount) setValue(trendName, "linkCurves", "curve" + j, "curve" + (j + 1)); } } else if(strpos(lines[i], "dp", 0) > 0) { i ++ ; for(int j = 1; j <= trendCount; j ++ ) { setValue(trendName, "connectDirectly", "curve" + j, lines[i ++ ]); } i -- ; } else if(strpos(lines[i], "curveName", 0) > 0) { i ++ ; for(int j = 1; j <= trendCount; j ++ ) { setValue(trendName, "curveLegendName", "curve" + j, lines[i ++ ]); } i -- ; } else if(strpos(lines[i], "end", 0) > 0) { setValue(trendName, "legendFont", "Arial Black, -1, 14, 0, 0, 0, 0, 0, 0, 0"); setValue(trendName, "trendRun"); } } }
string alertLevel(string key) { string tmpkey; switch(key) { case "-2": tmpkey = "断网";break; case "-1": tmpkey = "停机";break; case "0": tmpkey = "正常";break; case "1": tmpkey = "智能一级";break; case "2": tmpkey = "智能二级";break; case "3": tmpkey = "智能三级";break; case "4": tmpkey = "固定高报";break; case "5": tmpkey = "固定高高报";break; } return tmpkey; }
void showAlert() { string url = "http://10.217.3.118:18000/wepp_compressor_query_alert";
mapping data = makeMapping( "equipmentUuid", "1c43870a56802127f80a2829feb3294c", "pageNumber", 1, "size", 20 );
mapping result;
while(true) { netPost(url, makeMapping( "content", jsonEncode(data, false), "headers", makeMapping("Content-Type", "application/json; charset=utf-8") ), result );
if(mappingHasKey(result, "content")) if(mappingHasKey(result, "httpStatusText") && result["httpStatusText"] == "OK") if(mappingHasKey(result, "httpStatusCode") && result["httpStatusCode"] == 200) { mapping mData = jsonDecode(result["content"]); dyn_mapping dmData = mData["data"]["content"];
for(int i = 1; i <= dynlen(dmData); i ++ ) { mapping mItem = dmData[i];
if(linesize < 20) Table.appendLine("ID", i); linesize ++ ;
for(int k = 1; k <= mappinglen(mItem); k ++ ) { string key = mappingGetKey(mItem, k);
if(key != "alarmLevel" && key != "alarmEndTime" && key != "alarmStartTime" && key != "pointName") continue;
if(key == "alarmEndTime" || key == "alarmStartTime") { Table.cellValueRC(i - 1, key, formatTime("%y-%m-%d %H:%M:%S", (time)(mItem[key] / 1000))); } else if(key == "alarmLevel") { string tmpkey = alertLevel(mItem[key]); Table.cellValueRC(i - 1, key, tmpkey); } else { Table.cellValueRC(i - 1, key, mItem[key]); } } } }
if(linesize > 10000) linesize = 30;
delay(5); } }
|