How to use secondResponse method in storybook-root

Best JavaScript code snippet using storybook-root

api.controller.js

Source:api.controller.js Github

copy

Full Screen

1const axios = require("axios");2exports.entityGet = async (req, res) => {3 const { id, ids, parent, ancestor, attrs, ...queries } = req.query;4 await axios5 .get(`http://localhost:3002/entity/get`, {6 params: {7 id: id,8 ids: ids,9 attrs: attrs,10 parent: parent,11 ancestor: ancestor,12 ...queries,13 },14 })15 .then((response) => {16 if (response.data.data) {17 return res.send(response.data.data);18 }19 })20 .catch((err) => {21 return res.send(err.data);22 });23};24exports.entityAdd = async (req, res) => {25 const { data, alias, link, parent } = req.body;26 await axios27 .post(`http://localhost:3002/entity/add`, {28 data: data,29 alias: alias,30 link: link,31 parent: parent,32 })33 .then((response) => {34 if (response.data.data) {35 return res.send(response.data.data);36 }37 })38 .catch((err) => {39 return res.send(err.data);40 });41};42exports.entityUpdate = async (req, res) => {43 const { id, data, alias, link } = req.body;44 await axios45 .post(`http://localhost:3002/entity/update`, {46 id: id,47 data: data,48 alias: alias,49 link: link,50 })51 .then((response) => {52 if (response.data.data) {53 return res.send(response.data.data);54 }55 })56 .catch((err) => {57 return res.send(err.data);58 });59};60exports.entityDelete = async (req, res) => {61 const { id, ids, parent, ancestor, ...queries } = req.query;62 await axios63 .get(`http://localhost:3002/entity/delete`, {64 params: {65 id: id,66 ids: ids,67 parent: parent,68 ancestor: ancestor,69 ...queries,70 },71 })72 .then((response) => {73 if (response.data.data) {74 return res.send(response.data.data);75 }76 })77 .catch((err) => {78 return res.send(err.data);79 });80};81exports.entityGetRecords = async (req, res) => {82 const { id, attrs, interval, filter, date, from, to } = req.query;83 await axios84 .get(`http://localhost:3002/entity/get/records`, {85 params: {86 id: id,87 attrs: attrs,88 interval: interval,89 filter: filter,90 date: date,91 from: from,92 to: to,93 },94 })95 .then((response) => {96 if (response.data.data) {97 return res.send(response.data.data);98 }99 })100 .catch((err) => {101 return res.send(err.data);102 });103};104exports.provisionStatus = async (req, res) => {105 const { entity } = req.query;106 await axios107 .get(`http://localhost:3002/provision/status`, {108 params: {109 entity: entity,110 },111 })112 .then((response) => {113 if (response.data.data) {114 return res.send(response.data.data);115 }116 })117 .catch((err) => {118 return res.send(err.data);119 });120};121exports.provisionBegin = async (req, res) => {122 const { entity, timeout } = req.query;123 await axios124 .get(`http://localhost:3002/provision/begin`, {125 params: {126 entity: entity,127 timeout: timeout,128 },129 })130 .then((response) => {131 if (response.data.data) {132 return res.send(response.data.data);133 }134 })135 .catch((err) => {136 return res.send(err.data);137 });138};139exports.provisionRetrieve = async (req, res) => {140 const { entity } = req.query;141 await axios142 .get(`http://localhost:3002/provision/retrieve`, {143 params: {144 entity: entity,145 },146 })147 .then((response) => {148 if (response.data.data) {149 return res.send(response.data.data);150 }151 })152 .catch((err) => {153 return res.send(err.data);154 });155};156exports.entityGetRecordsDaily = async (req, res) => {157 const { id, attrs, date, interval } = req.query;158 await axios159 .get(`http://localhost:3002/entity/get/records`, {160 params: {161 id: id,162 attrs: attrs,163 interval: "day",164 filter: "all",165 date: date,166 },167 })168 .then((response) => {169 if (response.data.data) {170 let data = response.data.data;171 let objdata = {};172 attrs.split(",").map((item, index) => {173 if (data[`${item}`] !== null) {174 let result = [];175 let timestep = parseInt(interval);176 for (let i1 = 0; i1 <= 23; i1++) {177 for (let i2 = 0; i2 < 60; i2 = i2 + timestep) {178 let hourstr;179 let minstr;180 if (i1 < 10) {181 hourstr = "0" + i1.toString();182 } else {183 hourstr = i1.toString();184 }185 if (i2 < 10) {186 minstr = "0" + i2.toString();187 } else {188 minstr = i2.toString();189 }190 let timestr = hourstr + ":" + minstr;191 let flag = 0;192 if (data[`${item}`].length !== 0) {193 let dataItem = data[`${item}`][0].all;194 dataItem.every((item1, index1) => {195 //tach lay gio va phutS196 let a = item1.t.split("T")[1].slice(0, 5);197 if (a === timestr) {198 result.push({199 v: item1.v,200 t: timestr,201 });202 flag = 1;203 return false;204 }205 return true;206 });207 }208 if (flag === 0) {209 result.push({210 v: null,211 t: timestr,212 });213 }214 }215 }216 objdata[`${item}`] = result;217 } else {218 objdata[`${item}`] = null;219 }220 });221 return res.send(objdata);222 }223 })224 .catch((err) => {225 return res.send(err.data);226 });227};228exports.entityGetRecordsMonthly = async (req, res) => {229 const { id, attrs, month, interval } = req.query;230 await axios231 .get(`http://localhost:3002/entity/get/records`, {232 params: {233 id: id,234 attrs: attrs,235 interval: "day",236 filter: "first,last",237 date: month,238 },239 })240 .then((response) => {241 if (response.data.data) {242 let data = response.data.data;243 let objdata = {};244 let yearstr = month.split(",")[0];245 let monthstr = month.split(",")[1];246 let numDayofMonth;247 if (monthstr === "02") {248 numDayofMonth = 29;249 } else if (250 monthstr === "04" ||251 monthstr === "06" ||252 monthstr === "09" ||253 monthstr === "11"254 ) {255 numDayofMonth = 30;256 } else {257 numDayofMonth = 31;258 }259 attrs.split(",").map((item, index) => {260 if (data[`${item}`] !== null) {261 let result = [];262 for (let i = 1; i <= numDayofMonth; i++) {263 let daystr = String(i).padStart(2, "0");264 let timestr = yearstr + "-" + monthstr + "-" + daystr;265 let flag = 0;266 if (data[`${item}`].length !== 0) {267 let dataItem = data[`${item}`];268 dataItem.every((item1, index1) => {269 let a = item1.time.split("T")[0];270 if (a === timestr) {271 result.push({272 v: item1.last.v - item1.first.v,273 t: timestr,274 });275 flag = 1;276 return false;277 }278 return true;279 });280 }281 if (flag === 0) {282 result.push({283 v: null,284 t: timestr,285 });286 }287 }288 objdata[`${item}`] = result;289 } else {290 objdata[`${item}`] = null;291 }292 });293 return res.send(objdata);294 }295 })296 .catch((err) => {297 return res.send(err.data);298 });299};300exports.entityGetRecordsYearly = async (req, res) => {301 const { id, attrs, year } = req.query;302 await axios303 .get(`http://localhost:3002/entity/get/records`, {304 params: {305 id: id,306 attrs: attrs,307 interval: "month",308 filter: "first,last",309 date: year,310 },311 })312 .then((response) => {313 if (response.data.data) {314 let data = response.data.data;315 let objdata = {};316 let yearstr = year;317 attrs.split(",").map((item, index) => {318 if (data[`${item}`] !== null) {319 let result = [];320 for (let i = 1; i <= 12; i++) {321 let monthstr = String(i).padStart(2, "0");322 let timestr = year + "-" + monthstr;323 let flag = 0;324 if (data[`${item}`].length !== 0) {325 let dataItem = data[`${item}`];326 dataItem.every((item1, index1) => {327 let a = item1.time.split("T")[0].slice(0, 7);328 if (a === timestr) {329 result.push({330 v: item1.last.v - item1.first.v,331 t: timestr,332 });333 flag = 1;334 return false;335 }336 return true;337 });338 }339 if (flag === 0) {340 result.push({341 v: null,342 t: timestr,343 });344 }345 }346 objdata[`${item}`] = result;347 } else {348 objdata[`${item}`] = null;349 }350 });351 return res.send(objdata);352 }353 })354 .catch((err) => {355 return res.send(err.data);356 });357};358const roundfunction = (value, number) => {359 if (value === null) {360 return null;361 } else {362 let digit = 1 * Math.pow(10, number);363 return Math.round(value * digit) / digit;364 }365};366exports.getDataSiteViewChartInfor = async (req, res) => {367 const handleProduction = (data) => {368 let sum = null;369 data.map((item) => {370 if (371 item.EnergyMeterProduction !== null &&372 item.EnergyMeterProduction.length !== 0373 ) {374 sum =375 sum +376 item.EnergyMeterProduction[0].last.v -377 item.EnergyMeterProduction[0].first.v;378 }379 });380 return sum;381 };382 const handleActivePower = (data) => {383 let sum = null;384 data.map((item) => {385 if (item.ActivePower !== null && item.ActivePower.length !== 0) {386 sum = sum + item.ActivePower[0].last.v;387 }388 });389 return sum;390 };391 const handleIrradiation = (data) => {392 if (data.Irradiation !== null && data.Irradiation.length !== 0) {393 return data.Irradiation[0].last.v - data.Irradiation[0].first.v;394 } else {395 return null;396 }397 };398 const handleData = (data1, data2) => {399 let production = handleProduction(data1);400 let activepower = handleActivePower(data1);401 let irradiation = handleIrradiation(data2);402 if (time === "day") {403 let dataObj = {404 production: roundfunction(production, 3),405 yield: roundfunction(production / (1000 * capacity), 3),406 irradiation: roundfunction(irradiation, 3),407 powerratio: roundfunction((activepower * 100) / (1000 * capacity), 3),408 };409 return dataObj;410 } else {411 let dataObj = {412 production: roundfunction(production, 3),413 yield: roundfunction(production / (1000 * capacity), 3),414 irradiation: roundfunction(irradiation, 3),415 powerratio: roundfunction(416 (production * 100) / (capacity * irradiation),417 3418 ),419 };420 return dataObj;421 }422 };423 const { siteid, time, date } = req.query;424 const [capacity] = await Promise.all([425 axios426 .get(`http://localhost:3002/entity/get?id=${siteid}`)427 .then((response) => response.data.data.Capacity),428 ]);429 const [firstResponse] = await Promise.all([430 axios431 .get(432 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=EnergyMeter`433 )434 .then((response) => response.data.data),435 ]);436 const [secondResponse] = await Promise.all([437 axios438 .get(439 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=WeatherStation`440 )441 .then((response) => response.data.data),442 ]);443 let thirdResponse = [];444 let fourthResponse = { Irradiation: [] };445 if (firstResponse.length) {446 let url = [];447 firstResponse.map((item, index) => {448 url.push(449 axios450 .get(`http://localhost:3002/entity/get/records`, {451 params: {452 id: item.id,453 attrs: "EnergyMeterProduction,ActivePower",454 interval: time,455 filter: "first,last",456 date: date,457 },458 })459 .then((response) => response.data.data)460 );461 });462 thirdResponse = await Promise.all(url);463 }464 if (secondResponse.length) {465 [fourthResponse] = await Promise.all([466 axios467 .get(`http://localhost:3002/entity/get/records`, {468 params: {469 id: secondResponse[0].id,470 attrs: "Irradiation",471 interval: time,472 filter: "first,last",473 date: date,474 },475 })476 .then((response) => response.data.data),477 ]);478 }479 let dataObj = handleData(thirdResponse, fourthResponse);480 return res.send(dataObj);481};482exports.getDataSiteviewInverterTable = async (req, res) => {483 const handleData = (firstResponse, secondResponse, fourthResponse) => {484 if (time === "day") {485 let a = [];486 firstResponse.map((item, index) => {487 a.push({488 name: item.name,489 InverterProduction:490 secondResponse[index].InverterProduction !== null &&491 secondResponse[index].InverterProduction.length !== 0492 ? roundfunction(493 secondResponse[index].InverterProduction[0].last.v -494 secondResponse[index].InverterProduction[0].first.v,495 3496 )497 : null,498 InverterYield:499 secondResponse[index].InverterProduction !== null &&500 secondResponse[index].InverterProduction.length !== 0501 ? roundfunction(502 (secondResponse[index].InverterProduction[0].last.v -503 secondResponse[index].InverterProduction[0].first.v) /504 item.Capacity,505 3506 )507 : null,508 InverterPowerRatio:509 secondResponse[index].InverterActivePower !== null &&510 secondResponse[index].InverterActivePower.length !== 0511 ? roundfunction(512 secondResponse[index].InverterActivePower[0].last.v /513 item.Capacity,514 3515 )516 : null,517 });518 });519 return a;520 } else {521 let a = [];522 firstResponse.map((item, index) => {523 a.push({524 name: item.name,525 InverterProduction:526 secondResponse[index].InverterProduction !== null &&527 secondResponse[index].InverterProduction.length !== 0528 ? roundfunction(529 secondResponse[index].InverterProduction[0].last.v -530 secondResponse[index].InverterProduction[0].first.v,531 3532 )533 : null,534 InverterYield:535 secondResponse[index].InverterProduction !== null &&536 secondResponse[index].InverterProduction.length !== 0537 ? roundfunction(538 (secondResponse[index].InverterProduction[0].last.v -539 secondResponse[index].InverterProduction[0].first.v) /540 item.Capacity,541 3542 )543 : null,544 InverterPowerRatio:545 secondResponse[index].InverterProduction !== null &&546 secondResponse[index].InverterProduction.length !== 0 &&547 fourthResponse.Irradiation !== null &&548 fourthResponse.Irradiation.length !== 0549 ? roundfunction(550 ((secondResponse[index].InverterProduction[0].last.v -551 secondResponse[index].InverterProduction[0].first.v) *552 100) /553 ((fourthResponse.Irradiation[0].last.v -554 fourthResponse.Irradiation[0].first.v) *555 item.Capacity),556 3557 )558 : null,559 });560 });561 return a;562 }563 };564 const { siteid, time, date } = req.query;565 let url = [];566 const [firstResponse] = await Promise.all([567 axios568 .get(`http://localhost:3002/entity/get?ancestor=${siteid}&kind=Inverter`)569 .then((response) => response.data.data),570 ]);571 firstResponse.map((item, index) => {572 url.push(573 axios574 .get(`http://localhost:3002/entity/get/records`, {575 params: {576 id: item.id,577 attrs: "InverterProduction,InverterActivePower",578 interval: time,579 filter: "first,last",580 date: date,581 },582 })583 .then((response) => response.data.data)584 );585 });586 const secondResponse = await Promise.all(url);587 const [thirdResponse] = await Promise.all([588 axios589 .get(590 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=WeatherStation`591 )592 .then((response) => response.data.data),593 ]);594 let fourthResponse;595 if (thirdResponse.length) {596 [fourthResponse] = await Promise.all([597 axios598 .get(`http://localhost:3002/entity/get/records`, {599 params: {600 id: thirdResponse[0].id,601 attrs: "Irradiation",602 interval: time,603 filter: "first,last",604 date: date,605 },606 })607 .then((response) => response.data.data),608 ]);609 }610 let objData = handleData(firstResponse, secondResponse, fourthResponse);611 return res.send(objData);612};613exports.getDataSiteviewProduction = async (req, res) => {614 const handleSetInverterProduction = (data) => {615 let sum = null;616 data.map((item) => {617 if (618 item.InverterProduction !== null &&619 item.InverterProduction.length !== 0620 ) {621 sum =622 sum +623 item.InverterProduction[0].last.v -624 item.InverterProduction[0].first.v;625 }626 });627 return sum;628 };629 const handleSetSiteProduction = (data) => {630 let sum = null;631 data.map((item) => {632 if (633 item.EnergyMeterProduction !== null &&634 item.EnergyMeterProduction.length !== 0635 ) {636 sum =637 sum +638 item.EnergyMeterProduction[0].last.v -639 item.EnergyMeterProduction[0].first.v;640 }641 });642 return sum;643 };644 const handleData = (data1, data2) => {645 return {646 inverterProduction: roundfunction(handleSetInverterProduction(data1), 2),647 siteProduction: roundfunction(handleSetSiteProduction(data2), 2),648 };649 };650 const { siteid, time, date } = req.query;651 const [firstResponse] = await Promise.all([652 axios653 .get(`http://localhost:3002/entity/get?ancestor=${siteid}&kind=Inverter`)654 .then((response) => response.data.data),655 ]);656 const [secondResponse] = await Promise.all([657 axios658 .get(659 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=EnergyMeter`660 )661 .then((response) => response.data.data),662 ]);663 let url1 = [];664 let url2 = [];665 if (firstResponse.length) {666 firstResponse.map((item, index) => {667 url1.push(668 axios669 .get(`http://localhost:3002/entity/get/records`, {670 params: {671 id: item.id,672 attrs: "InverterProduction,InverterActivePower",673 interval: time,674 filter: "first,last",675 date: date,676 },677 })678 .then((response) => response.data.data)679 );680 });681 }682 const thirdResponse = await Promise.all(url1);683 if (secondResponse.length) {684 secondResponse.map((item, index) => {685 url2.push(686 axios687 .get(`http://localhost:3002/entity/get/records`, {688 params: {689 id: item.id,690 attrs: "EnergyMeterProduction",691 interval: time,692 filter: "first,last",693 date: date,694 },695 })696 .then((response) => response.data.data)697 );698 });699 }700 const fourthResponse = await Promise.all(url2);701 let dataObj = handleData(thirdResponse, fourthResponse);702 return res.send(dataObj);703};704const getDataDaily1 = async (id, attrs, date, interval) => {705 const [data] = await Promise.all([706 axios707 .get(`http://localhost:3002/entity/get/records`, {708 params: {709 id: id,710 attrs: attrs,711 interval: "day",712 filter: "all",713 date: date,714 },715 })716 .then((response) => response.data.data),717 ]);718 let objdata = {};719 attrs.split(",").map((item, index) => {720 if (data[`${item}`] !== null) {721 let result = [];722 let timestep = parseInt(interval);723 for (let i1 = 0; i1 <= 23; i1++) {724 for (let i2 = 0; i2 < 60; i2 = i2 + timestep) {725 let hourstr;726 let minstr;727 if (i1 < 10) {728 hourstr = "0" + i1.toString();729 } else {730 hourstr = i1.toString();731 }732 if (i2 < 10) {733 minstr = "0" + i2.toString();734 } else {735 minstr = i2.toString();736 }737 let timestr = hourstr + ":" + minstr;738 let flag = 0;739 if (data[`${item}`].length !== 0) {740 let dataItem = data[`${item}`][0].all;741 dataItem.every((item1, index1) => {742 //tach lay gio va phutS743 let a = item1.t.split("T")[1].slice(0, 5);744 if (a === timestr) {745 result.push({746 v: item1.v,747 t: timestr,748 });749 flag = 1;750 return false;751 }752 return true;753 });754 }755 if (flag === 0) {756 result.push({757 v: null,758 t: timestr,759 });760 }761 }762 }763 objdata[`${item}`] = result;764 } else {765 objdata[`${item}`] = null;766 }767 });768 return objdata;769};770const getDataDaily = async (id, attrs, date, interval) => {771 const [data] = await Promise.all([772 axios773 .get(`http://localhost:3002/entity/get/records`, {774 params: {775 id: id,776 attrs: attrs,777 interval: interval,778 filter: "first",779 date: date,780 },781 })782 .then((response) => response.data.data),783 ]);784 let objdata = {};785 attrs.split(",").map((item, index) => {786 if (data[`${item}`] !== null) {787 let result = [];788 data[`${item}`].map((dataItem) => {789 result.push({790 v: dataItem.first.v,791 t: dataItem.time.split("T")[1].slice(0, 5),792 });793 });794 objdata[`${item}`] = result;795 } else {796 objdata[`${item}`] = null;797 }798 });799 return objdata;800};801exports.getDataSiteviewLineColumnChart = async (req, res) => {802 const handleProduction = (data) => {803 let array = [];804 if (data.length !== 0) {805 let length = data[0].EnergyMeterProduction.length;806 for (let i = 0; i < length; i++) {807 let sum = null;808 let time = "";809 data.map((item) => {810 if (item.EnergyMeterProduction[i].v !== null) {811 sum = sum + item.EnergyMeterProduction[i].v;812 }813 time = item.EnergyMeterProduction[i].t;814 });815 array.push({816 v: sum,817 t: time,818 });819 }820 }821 return array;822 };823 const handleData = (item1, item2) => {824 let production = handleProduction(item1);825 let prevalue;826 let data1 = [];827 let data2 = [];828 let data3 = [];829 let sign1 = false;830 let sign2 = false;831 production.map((item, index) => {832 if (item.v === null) {833 data1.push(item.v);834 } else {835 if (sign1 === false) {836 data1.push(item.v - item.v);837 sign1 = true;838 } else {839 data1.push(roundfunction(item.v - prevalue, 2));840 }841 prevalue = item.v;842 }843 data3.push(item.t);844 });845 item2.Irradiation.map((item, index) => {846 if (item.v === null) {847 data2.push(item.v);848 } else {849 if (sign2 === false) {850 data2.push(item.v - item.v);851 sign2 = true;852 } else {853 data2.push(roundfunction(item.v - prevalue, 2));854 }855 prevalue = item.v;856 }857 });858 return {859 production: data1,860 irradiation: data2,861 label: data3,862 };863 };864 const { siteid, date } = req.query;865 const [firstResponse] = await Promise.all([866 axios867 .get(868 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=EnergyMeter`869 )870 .then((response) => response.data.data),871 ]);872 const [secondResponse] = await Promise.all([873 axios874 .get(875 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=WeatherStation`876 )877 .then((response) => response.data.data),878 ]);879 let thirdResponse = [];880 let fourthResponse = { Irradiation: [] };881 if (firstResponse.length) {882 for (let i = 0; i < firstResponse.length; i++) {883 let a = await getDataDaily(884 firstResponse[i].id,885 "EnergyMeterProduction",886 date,887 "hour"888 );889 thirdResponse.push(a);890 }891 }892 if (secondResponse.length) {893 fourthResponse = await getDataDaily(894 secondResponse[0].id,895 "Irradiation",896 date,897 "hour"898 );899 }900 let objdata = handleData(thirdResponse, fourthResponse);901 return res.send(objdata);902};903exports.getDataSiteviewLineChart = async (req, res) => {904 const handleActivePower = (data) => {905 let array = [];906 if (data.length !== 0) {907 let length = data[0].ActivePower.length;908 for (let i = 0; i < length; i++) {909 let sum = null;910 let time = "";911 data.map((item) => {912 if (item.ActivePower[i].v !== null) {913 sum = sum + item.ActivePower[i].v;914 }915 time = item.ActivePower[i].t;916 });917 array.push({918 v: sum,919 t: time,920 });921 }922 }923 return array;924 };925 const handleData = (item1, item2) => {926 let data1 = [];927 let data2 = [];928 let data3 = [];929 let activepower = handleActivePower(item1);930 activepower.map((item) => {931 if (item.v !== null) {932 data1.push(roundfunction(item.v, 2));933 } else {934 data1.push(item.v);935 }936 data3.push(item.t);937 });938 item2.GHI.map((item) => {939 if (item.v !== null) {940 data2.push(roundfunction(item.v, 2));941 } else {942 data2.push(item.v);943 }944 });945 return {946 activePower: data1,947 GHI: data2,948 label: data3,949 };950 };951 const { siteid, date } = req.query;952 const [firstResponse] = await Promise.all([953 axios954 .get(955 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=EnergyMeter`956 )957 .then((response) => response.data.data),958 ]);959 const [secondResponse] = await Promise.all([960 axios961 .get(962 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=WeatherStation`963 )964 .then((response) => response.data.data),965 ]);966 let thirdResponse = [];967 let fourthResponse = { GHI: [] };968 if (firstResponse.length) {969 for (let i = 0; i < firstResponse.length; i++) {970 let a = await getDataDaily(971 firstResponse[i].id,972 "ActivePower",973 date,974 "10m"975 );976 thirdResponse.push(a);977 }978 }979 if (secondResponse.length) {980 fourthResponse = await getDataDaily(981 secondResponse[0].id,982 "GHI",983 date,984 "10m"985 );986 }987 let objdata = handleData(thirdResponse, fourthResponse);988 return res.send(objdata);989};990const getDataMonthly = async (id, attrs, date) => {991 const [data] = await Promise.all([992 axios993 .get(`http://localhost:3002/entity/get/records`, {994 params: {995 id: id,996 attrs: attrs,997 interval: "day",998 filter: "first,last",999 date: date,1000 },1001 })1002 .then((response) => response.data.data),1003 ]);1004 let objdata = {};1005 let yearstr = date.split(",")[0];1006 let monthstr = date.split(",")[1];1007 let numDayofMonth;1008 if (monthstr === "02") {1009 numDayofMonth = 29;1010 } else if (1011 monthstr === "04" ||1012 monthstr === "06" ||1013 monthstr === "09" ||1014 monthstr === "11"1015 ) {1016 numDayofMonth = 30;1017 } else {1018 numDayofMonth = 31;1019 }1020 attrs.split(",").map((item, index) => {1021 if (data[`${item}`] !== null) {1022 let result = [];1023 for (let i = 1; i <= numDayofMonth; i++) {1024 let daystr = String(i).padStart(2, "0");1025 let timestr = yearstr + "-" + monthstr + "-" + daystr;1026 let flag = 0;1027 if (data[`${item}`].length !== 0) {1028 let dataItem = data[`${item}`];1029 dataItem.every((item1, index1) => {1030 let a = item1.time.split("T")[0];1031 if (a === timestr) {1032 result.push({1033 v: item1.last.v - item1.first.v,1034 t: timestr,1035 });1036 flag = 1;1037 return false;1038 }1039 return true;1040 });1041 }1042 if (flag === 0) {1043 result.push({1044 v: null,1045 t: timestr,1046 });1047 }1048 }1049 objdata[`${item}`] = result;1050 } else {1051 objdata[`${item}`] = null;1052 }1053 });1054 return objdata;1055};1056exports.getDataSiteviewLineColumnChart1 = async (req, res) => {1057 const handleProduction = (data) => {1058 let array = [];1059 if (data.length !== 0) {1060 let length = data[0].EnergyMeterProduction.length;1061 for (let i = 0; i < length; i++) {1062 let sum = null;1063 let time = "";1064 data.map((item) => {1065 if (item.EnergyMeterProduction[i].v !== null) {1066 sum = sum + item.EnergyMeterProduction[i].v;1067 }1068 time = item.EnergyMeterProduction[i].t;1069 });1070 array.push({1071 v: sum,1072 t: time,1073 });1074 }1075 }1076 return array;1077 };1078 const handleData = (item1, item2) => {1079 let data1 = [];1080 let data2 = [];1081 let data3 = [];1082 let production = handleProduction(item1);1083 production.map((item, index) => {1084 if (item.v === null) {1085 data1.push(null);1086 } else {1087 data1.push(roundfunction(item.v / (1000 * capacity), 2));1088 }1089 data3.push(item.t);1090 });1091 item2.Irradiation.map((item, index) => {1092 if (item.v !== null) {1093 data2.push(roundfunction(item.v, 2));1094 } else {1095 data2.push(item.v);1096 }1097 });1098 return {1099 yield: data1,1100 irradiation: data2,1101 label: data3,1102 };1103 };1104 const { siteid, date } = req.query;1105 const [capacity] = await Promise.all([1106 axios1107 .get(`http://localhost:3002/entity/get?id=${siteid}`)1108 .then((response) => response.data.data.Capacity),1109 ]);1110 const [firstResponse] = await Promise.all([1111 axios1112 .get(1113 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=EnergyMeter`1114 )1115 .then((response) => response.data.data),1116 ]);1117 const [secondResponse] = await Promise.all([1118 axios1119 .get(1120 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=WeatherStation`1121 )1122 .then((response) => response.data.data),1123 ]);1124 let thirdResponse = [];1125 let fourthResponse = { Irradiation: [] };1126 if (firstResponse.length) {1127 for (let i = 0; i < firstResponse.length; i++) {1128 let a = await getDataMonthly(1129 firstResponse[i].id,1130 "EnergyMeterProduction",1131 date1132 );1133 thirdResponse.push(a);1134 }1135 }1136 if (secondResponse.length) {1137 fourthResponse = await getDataMonthly(1138 secondResponse[0].id,1139 "Irradiation",1140 date1141 );1142 }1143 let objdata = handleData(thirdResponse, fourthResponse);1144 return res.send(objdata);1145};1146exports.getDataSiteviewLineChart1 = async (req, res) => {1147 const handleProduction = (data) => {1148 let array = [];1149 if (data.length !== 0) {1150 let length = data[0].EnergyMeterProduction.length;1151 for (let i = 0; i < length; i++) {1152 let sum = null;1153 let time = "";1154 data.map((item) => {1155 if (item.EnergyMeterProduction[i].v !== null) {1156 sum = sum + item.EnergyMeterProduction[i].v;1157 }1158 time = item.EnergyMeterProduction[i].t;1159 });1160 array.push({1161 v: sum,1162 t: time,1163 });1164 }1165 }1166 return array;1167 };1168 const handleData = (item1, item2) => {1169 let data1 = [];1170 let data3 = [];1171 let production = handleProduction(item1);1172 for (let i = 0; i < production.length; i++) {1173 if (production[i].v !== null && item2.Irradiation[i].v !== null) {1174 data1.push(1175 roundfunction(1176 (production[i].v * 100) / (capacity * item2.Irradiation[i].v),1177 21178 )1179 );1180 } else {1181 data1.push(null);1182 }1183 data3.push(production[i].t);1184 }1185 return {1186 PR: data1,1187 label: data3,1188 };1189 };1190 const { siteid, date } = req.query;1191 const [capacity] = await Promise.all([1192 axios1193 .get(`http://localhost:3002/entity/get?id=${siteid}`)1194 .then((response) => response.data.data.Capacity),1195 ]);1196 const [firstResponse] = await Promise.all([1197 axios1198 .get(1199 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=EnergyMeter`1200 )1201 .then((response) => response.data.data),1202 ]);1203 const [secondResponse] = await Promise.all([1204 axios1205 .get(1206 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=WeatherStation`1207 )1208 .then((response) => response.data.data),1209 ]);1210 let thirdResponse = [];1211 let fourthResponse = { Irradiation: [] };1212 if (firstResponse.length) {1213 for (let i = 0; i < firstResponse.length; i++) {1214 let a = await getDataMonthly(1215 firstResponse[i].id,1216 "EnergyMeterProduction",1217 date1218 );1219 thirdResponse.push(a);1220 }1221 }1222 if (secondResponse.length) {1223 fourthResponse = await getDataMonthly(1224 secondResponse[0].id,1225 "Irradiation",1226 date1227 );1228 }1229 let objdata = handleData(thirdResponse, fourthResponse);1230 return res.send(objdata);1231};1232const getDataYearly = async (id, attrs, date) => {1233 const [data] = await Promise.all([1234 axios1235 .get(`http://localhost:3002/entity/get/records`, {1236 params: {1237 id: id,1238 attrs: attrs,1239 interval: "month",1240 filter: "first,last",1241 date: date,1242 },1243 })1244 .then((response) => response.data.data),1245 ]);1246 let objdata = {};1247 let yearstr = date;1248 attrs.split(",").map((item, index) => {1249 if (data[`${item}`] !== null) {1250 let result = [];1251 for (let i = 1; i <= 12; i++) {1252 let monthstr = String(i).padStart(2, "0");1253 let timestr = yearstr + "-" + monthstr;1254 let flag = 0;1255 if (data[`${item}`].length !== 0) {1256 let dataItem = data[`${item}`];1257 dataItem.every((item1, index1) => {1258 let a = item1.time.split("T")[0].slice(0, 7);1259 if (a === timestr) {1260 result.push({1261 v: item1.last.v - item1.first.v,1262 t: timestr,1263 });1264 flag = 1;1265 return false;1266 }1267 return true;1268 });1269 }1270 if (flag === 0) {1271 result.push({1272 v: null,1273 t: timestr,1274 });1275 }1276 }1277 objdata[`${item}`] = result;1278 } else {1279 objdata[`${item}`] = null;1280 }1281 });1282 return objdata;1283};1284exports.getDataSiteviewLineColumnChart2 = async (req, res) => {1285 const handleProduction = (data) => {1286 let array = [];1287 if (data.length !== 0) {1288 let length = data[0].EnergyMeterProduction.length;1289 for (let i = 0; i < length; i++) {1290 let sum = null;1291 let time = "";1292 data.map((item) => {1293 if (item.EnergyMeterProduction[i].v !== null) {1294 sum = sum + item.EnergyMeterProduction[i].v;1295 }1296 time = item.EnergyMeterProduction[i].t;1297 });1298 array.push({1299 v: sum,1300 t: time,1301 });1302 }1303 }1304 return array;1305 };1306 const { siteid, date } = req.query;1307 let label = [1308 "2021-01",1309 "2021-02",1310 "2021-03",1311 "2021-04",1312 "2021-05",1313 "2021-06",1314 "2021-07",1315 "2021-08",1316 "2021-09",1317 "2021-10",1318 "2021-11",1319 "2021-12",1320 ];1321 const [firstResponse] = await Promise.all([1322 axios1323 .get(`http://localhost:3002/entity/get?id=${siteid}`)1324 .then((response) => response.data.data.productionBudget),1325 ]);1326 let data_2 = [];1327 firstResponse.map((item) => {1328 if (item.year === parseInt(date)) {1329 item.value.map((item1) => {1330 data_2.push(parseInt(item1));1331 });1332 }1333 });1334 const [secondResponse] = await Promise.all([1335 axios1336 .get(1337 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=EnergyMeter`1338 )1339 .then((response) => response.data.data),1340 ]);1341 let data_1 = [];1342 let thirdResponse = [];1343 if (secondResponse.length) {1344 for (let i = 0; i < secondResponse.length; i++) {1345 let a = await getDataYearly(1346 secondResponse[i].id,1347 "EnergyMeterProduction",1348 date1349 );1350 thirdResponse.push(a);1351 }1352 let production = handleProduction(thirdResponse);1353 production.map((item) => {1354 if (item.v !== null) {1355 data_1.push(roundfunction(item.v, 2));1356 } else {1357 data_1.push(item.v);1358 }1359 });1360 }1361 let data_3 = [];1362 label.map((item, index) => {1363 if (data_1[index] !== null) {1364 data_3.push(Math.round((data_1[index] * 100) / data_2[index]));1365 } else {1366 data_3.push(null);1367 }1368 });1369 let objdata = {1370 actualProduction: data_1,1371 budgetProduction: data_2,1372 completionRate: data_3,1373 label: label,1374 };1375 return res.send(objdata);1376};1377exports.getDataSiteviewLineChart2 = async (req, res) => {1378 const handleProduction = (data) => {1379 let array = [];1380 if (data.length !== 0) {1381 let length = data[0].EnergyMeterProduction.length;1382 for (let i = 0; i < length; i++) {1383 let sum = null;1384 let time = "";1385 data.map((item) => {1386 if (item.EnergyMeterProduction[i].v !== null) {1387 sum = sum + item.EnergyMeterProduction[i].v;1388 }1389 time = item.EnergyMeterProduction[i].t;1390 });1391 array.push({1392 v: sum,1393 t: time,1394 });1395 }1396 }1397 return array;1398 };1399 const { siteid, date } = req.query;1400 let label = [1401 "2021-01",1402 "2021-02",1403 "2021-03",1404 "2021-04",1405 "2021-05",1406 "2021-06",1407 "2021-07",1408 "2021-08",1409 "2021-09",1410 "2021-10",1411 "2021-11",1412 "2021-12",1413 ];1414 const [capacity] = await Promise.all([1415 axios1416 .get(`http://localhost:3002/entity/get?id=${siteid}`)1417 .then((response) => response.data.data.Capacity),1418 ]);1419 const [firstResponse] = await Promise.all([1420 axios1421 .get(`http://localhost:3002/entity/get?id=${siteid}`)1422 .then((response) => response.data.data.irradiationBudget),1423 ]);1424 let data_2 = [];1425 firstResponse.map((item) => {1426 if (item.year === parseInt(date)) {1427 item.value.map((item1) => {1428 data_2.push(parseInt(item1));1429 });1430 }1431 });1432 const [secondResponse] = await Promise.all([1433 axios1434 .get(1435 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=WeatherStation`1436 )1437 .then((response) => response.data.data),1438 ]);1439 let data_1 = [];1440 let data_3 = [];1441 if (secondResponse.length) {1442 const thirdResponse = await getDataYearly(1443 secondResponse[0].id,1444 "Irradiation",1445 date1446 );1447 thirdResponse.Irradiation.map((item) => {1448 if (item.v !== null) {1449 data_1.push(roundfunction(item.v, 2));1450 } else {1451 data_1.push(item.v);1452 }1453 });1454 }1455 const [fourthResponse] = await Promise.all([1456 axios1457 .get(1458 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=EnergyMeter`1459 )1460 .then((response) => response.data.data),1461 ]);1462 let fifthResponse = [];1463 if (fourthResponse.length) {1464 for (let i = 0; i < fourthResponse.length; i++) {1465 let a = await getDataYearly(1466 fourthResponse[i].id,1467 "EnergyMeterProduction",1468 date1469 );1470 fifthResponse.push(a);1471 }1472 let production = handleProduction(fifthResponse);1473 production.map((item) => {1474 if (item.v !== null) {1475 data_3.push(roundfunction(item.v / (1000 * capacity), 2));1476 } else {1477 data_3.push(null);1478 }1479 });1480 }1481 let objdata = {1482 actualIrradiation: data_1,1483 theoreticalIrradiation: data_2,1484 yield: data_3,1485 label: label,1486 };1487 return res.send(objdata);1488};1489exports.getDataSiteList = async (req, res) => {1490 const handleProduction = (data) => {1491 let sum = null;1492 data.map((item) => {1493 if (1494 item.EnergyMeterProduction !== null &&1495 item.EnergyMeterProduction.length !== 01496 ) {1497 sum =1498 sum +1499 item.EnergyMeterProduction[0].last.v -1500 item.EnergyMeterProduction[0].first.v;1501 }1502 });1503 return sum;1504 };1505 const handleIrradiation = (data) => {1506 let sum = null;1507 data.map((item) => {1508 if (item.Irradiation !== null && item.Irradiation.length !== 0) {1509 sum = sum + item.Irradiation[0].last.v - item.Irradiation[0].first.v;1510 }1511 });1512 return sum;1513 };1514 const handleActivePower = (data) => {1515 let sum = null;1516 data.map((item) => {1517 if (item.ActivePower !== null && item.ActivePower.length !== 0) {1518 sum = sum + item.ActivePower[0].last.v;1519 }1520 });1521 return sum;1522 };1523 const handleIrradiance = (data) => {1524 let sum = null;1525 data.map((item) => {1526 if (item.GHI !== null && item.GHI.length !== 0) {1527 sum = sum + item.GHI[0].last.v;1528 }1529 });1530 return sum;1531 };1532 const { siteids, date } = req.query;1533 const entitiesget = await Promise.all(1534 siteids.map((item, index) =>1535 axios1536 .get(`http://localhost:3002/entity/get?id=${item}`)1537 .then((response) => response.data.data)1538 )1539 );1540 let url1 = [];1541 entitiesget.map((item, index) => {1542 url1.push(1543 axios1544 .get(1545 `http://localhost:3002/entity/get?ancestor=${item.id}&kind=EnergyMeter`1546 )1547 .then((response) => response.data.data)1548 );1549 });1550 const firstResponse = await Promise.all(url1);1551 let url2 = [];1552 entitiesget.map((item, index) => {1553 url2.push(1554 axios1555 .get(1556 `http://localhost:3002/entity/get?ancestor=${item.id}&kind=WeatherStation`1557 )1558 .then((response) => response.data.data)1559 );1560 });1561 const secondResponse = await Promise.all(url2);1562 let productiondata = [];1563 let activepowerdata = [];1564 let irradiationdata = [];1565 let ghidata = [];1566 if (firstResponse.length) {1567 for (let i = 0; i < firstResponse.length; i++) {1568 if (firstResponse[i].length) {1569 let a = [];1570 firstResponse[i].map((item1) => {1571 a.push(1572 axios1573 .get(`http://localhost:3002/entity/get/records`, {1574 params: {1575 id: item1.id,1576 attrs: "EnergyMeterProduction,ActivePower",1577 interval: "day",1578 filter: "first,last",1579 date: date,1580 },1581 })1582 .then((response) => response.data.data)1583 );1584 });1585 const responseitem = await Promise.all(a);1586 productiondata.push(handleProduction(responseitem));1587 activepowerdata.push(handleActivePower(responseitem));1588 } else {1589 productiondata.push(handleProduction([]));1590 activepowerdata.push(handleActivePower([]));1591 }1592 }1593 }1594 if (secondResponse.length) {1595 for (let i = 0; i < secondResponse.length; i++) {1596 if (secondResponse[i].length) {1597 let a = [];1598 secondResponse[i].map((item1) => {1599 a.push(1600 axios1601 .get(`http://localhost:3002/entity/get/records`, {1602 params: {1603 id: item1.id,1604 attrs: "Irradiation,GHI",1605 interval: "day",1606 filter: "first,last",1607 date: date,1608 },1609 })1610 .then((response) => response.data.data)1611 );1612 });1613 const responseitem = await Promise.all(a);1614 irradiationdata.push(handleIrradiation(responseitem));1615 ghidata.push(handleIrradiance(responseitem));1616 } else {1617 irradiationdata.push(handleIrradiation([]));1618 ghidata.push(handleIrradiance([]));1619 }1620 }1621 }1622 let objdata = [];1623 entitiesget.map((item, index) => {1624 objdata.push({1625 name: item.name,1626 id: item.id,1627 capacity: item.Capacity,1628 operation_state: "Normal",1629 connection_state: "--",1630 production_today: roundfunction(productiondata[index], 2),1631 active_power: roundfunction(activepowerdata[index], 2),1632 power_ratio: roundfunction(1633 (activepowerdata[index] * 100) / (1000 * item.Capacity),1634 21635 ),1636 irradiation: roundfunction(irradiationdata[index], 2),1637 irradiance: roundfunction(ghidata[index], 2),1638 });1639 });1640 return res.send(objdata);1641};1642exports.getDataLeaderboardProduction = async (req, res) => {1643 const handleProduction = (data) => {1644 let sum = null;1645 data.map((item) => {1646 item.EnergyMeterProduction.map((item1) => {1647 sum = sum + item1.v;1648 });1649 });1650 return sum;1651 };1652 const handleProductionMonth = (data) => {1653 let a = [];1654 for (let i = 0; i < 12; i++) {1655 let sum = null;1656 data.map((item) => {1657 sum = sum + item.EnergyMeterProduction[i].v;1658 });1659 a.push(sum);1660 }1661 return a;1662 };1663 const { siteids, date } = req.query;1664 let entities = await Promise.all(1665 siteids.map((item, index) =>1666 axios1667 .get(`http://localhost:3002/entity/get?id=${item}`)1668 .then((response) => response.data.data)1669 )1670 );1671 let url1 = [];1672 entities.map((item, index) => {1673 url1.push(1674 axios1675 .get(1676 `http://localhost:3002/entity/get?ancestor=${item.id}&kind=EnergyMeter`1677 )1678 .then((response) => response.data.data)1679 );1680 });1681 let productionbudget = [];1682 entities.map((item) => {1683 let sum = null;1684 item.productionBudget.map((item) => {1685 if (item.year == date) {1686 item.value.map((item1) => {1687 sum = sum + parseFloat(item1);1688 });1689 }1690 });1691 productionbudget.push(sum);1692 });1693 let totalproductionbudgetmonth = [];1694 for (let i = 0; i < 12; i++) {1695 let sum = null;1696 entities.map((item) => {1697 item.productionBudget.map((item) => {1698 if (item.year == date) {1699 sum = sum + parseFloat(item.value[i]);1700 }1701 });1702 });1703 totalproductionbudgetmonth.push(sum);1704 }1705 const firstResponse = await Promise.all(url1);1706 let productiondata = [];1707 let productiondataMonth = [];1708 if (firstResponse.length) {1709 for (let i = 0; i < firstResponse.length; i++) {1710 if (firstResponse[i].length) {1711 let responseitem = [];1712 for (let j = 0; j < firstResponse[i].length; j++) {1713 let a = await getDataYearly(1714 firstResponse[i][j].id,1715 "EnergyMeterProduction",1716 date1717 );1718 responseitem.push(a);1719 }1720 productiondata.push(handleProduction(responseitem));1721 productiondataMonth.push(handleProductionMonth(responseitem));1722 } else {1723 productiondata.push(null);1724 }1725 }1726 }1727 //1728 let completionrate = [];1729 productionbudget.map((item, index) => {1730 completionrate.push(roundfunction((productiondata[index] * 100) / item, 2));1731 });1732 let totalproductiondata = null;1733 productiondata.map((item) => {1734 totalproductiondata = totalproductiondata + item;1735 });1736 let totalproductionbudget = null;1737 productionbudget.map((item) => {1738 totalproductionbudget = totalproductionbudget + item;1739 });1740 //1741 let totalCompleteRate = roundfunction(1742 (totalproductiondata * 100) / totalproductionbudget,1743 21744 );1745 let totalproductiondatamonth = [];1746 for (let i = 0; i < 12; i++) {1747 let sum = null;1748 productiondataMonth.map((item) => {1749 sum = sum + item[i];1750 });1751 totalproductiondatamonth.push(sum);1752 }1753 //1754 let totalcompleteratemonth = [];1755 for (let i = 0; i < 12; i++) {1756 totalcompleteratemonth.push(1757 roundfunction(1758 (totalproductiondatamonth[i] * 100) / totalproductionbudgetmonth[i],1759 21760 )1761 );1762 }1763 let objdata = {1764 completionrate: completionrate,1765 totalcompletionrate: totalCompleteRate,1766 totalcompleteratemonth: totalcompleteratemonth,1767 };1768 return res.send(objdata);1769};1770exports.getDataLeaderboardPerformanceRanking = async (req, res) => {1771 const handleProduction = (data) => {1772 let sum = null;1773 data.map((item) => {1774 if (1775 item.EnergyMeterProduction !== null &&1776 item.EnergyMeterProduction.length !== 01777 ) {1778 sum =1779 sum +1780 item.EnergyMeterProduction[0].last.v -1781 item.EnergyMeterProduction[0].first.v;1782 }1783 });1784 return sum;1785 };1786 const handleIrradiation = (data) => {1787 let sum = null;1788 data.map((item) => {1789 if (item.Irradiation !== null && item.Irradiation.length !== 0) {1790 sum = sum + item.Irradiation[0].last.v - item.Irradiation[0].first.v;1791 }1792 });1793 return sum;1794 };1795 const { siteids, time, date, measurement } = req.query;1796 const entitiesget = await Promise.all(1797 siteids.map((item, index) =>1798 axios1799 .get(`http://localhost:3002/entity/get?id=${item}`)1800 .then((response) => response.data.data)1801 )1802 );1803 let url1 = [];1804 entitiesget.map((item, index) => {1805 url1.push(1806 axios1807 .get(1808 `http://localhost:3002/entity/get?ancestor=${item.id}&kind=EnergyMeter`1809 )1810 .then((response) => response.data.data)1811 );1812 });1813 const firstResponse = await Promise.all(url1);1814 let url2 = [];1815 entitiesget.map((item, index) => {1816 url2.push(1817 axios1818 .get(1819 `http://localhost:3002/entity/get?ancestor=${item.id}&kind=WeatherStation`1820 )1821 .then((response) => response.data.data)1822 );1823 });1824 let productiondata = [];1825 let irradiationdata = [];1826 const secondResponse = await Promise.all(url2);1827 if (firstResponse.length) {1828 for (let i = 0; i < firstResponse.length; i++) {1829 if (firstResponse[i].length) {1830 let a = [];1831 firstResponse[i].map((item1) => {1832 a.push(1833 axios1834 .get(`http://localhost:3002/entity/get/records`, {1835 params: {1836 id: item1.id,1837 attrs: "EnergyMeterProduction",1838 interval: time,1839 filter: "first,last",1840 date: date,1841 },1842 })1843 .then((response) => response.data.data)1844 );1845 });1846 const responseitem = await Promise.all(a);1847 productiondata.push(handleProduction(responseitem));1848 } else {1849 productiondata.push(handleProduction([]));1850 }1851 }1852 }1853 if (secondResponse.length) {1854 for (let i = 0; i < secondResponse.length; i++) {1855 if (secondResponse[i].length) {1856 let a = [];1857 secondResponse[i].map((item1) => {1858 a.push(1859 axios1860 .get(`http://localhost:3002/entity/get/records`, {1861 params: {1862 id: item1.id,1863 attrs: "Irradiation",1864 interval: time,1865 filter: "first,last",1866 date: date,1867 },1868 })1869 .then((response) => response.data.data)1870 );1871 });1872 const responseitem = await Promise.all(a);1873 irradiationdata.push(handleIrradiation(responseitem));1874 } else {1875 irradiationdata.push(handleIrradiation([]));1876 }1877 }1878 }1879 let data1 = [];1880 let data2 = [];1881 entitiesget.map((item, index) => {1882 data2.push(item.name);1883 if (measurement === "Yield") {1884 if (productiondata[index] === null) {1885 data1.push(null);1886 } else {1887 data1.push(1888 roundfunction(productiondata[index] / (1000 * item.Capacity), 2)1889 );1890 }1891 }1892 if (measurement === "PR") {1893 if (productiondata[index] === null || irradiationdata[index] === null) {1894 data1.push(null);1895 } else {1896 data1.push(1897 roundfunction(1898 (productiondata[index] * 100) /1899 (item.Capacity * irradiationdata[index]),1900 21901 )1902 );1903 }1904 }1905 });1906 let objdata = {1907 data1: data1,1908 data2: data2,1909 };1910 return res.send(objdata);1911};1912exports.getDataFleetviewOverview = async (req, res) => {1913 const handleProduction = (data) => {1914 let sum = null;1915 data.map((item) => {1916 if (1917 item.EnergyMeterProduction !== null &&1918 item.EnergyMeterProduction.length !== 01919 ) {1920 sum =1921 sum +1922 item.EnergyMeterProduction[0].last.v -1923 item.EnergyMeterProduction[0].first.v;1924 }1925 });1926 return sum;1927 };1928 const handleActivePower = (data) => {1929 let sum = null;1930 data.map((item) => {1931 if (item.ActivePower !== null && item.ActivePower.length !== 0) {1932 sum = sum + item.ActivePower[0].last.v;1933 }1934 });1935 return sum;1936 };1937 const handleIrradiation = (data) => {1938 if (data.Irradiation !== null && data.Irradiation.length !== 0) {1939 return data.Irradiation[0].last.v - data.Irradiation[0].first.v;1940 } else {1941 return null;1942 }1943 };1944 const handleData = (data1, data2) => {1945 let production = handleProduction(data1);1946 let activepower = handleActivePower(data1);1947 let irradiation = handleIrradiation(data2);1948 return {1949 production: roundfunction(production / 1000, 2),1950 yield: roundfunction(production / (1000 * capacity), 2),1951 irradiation: roundfunction(irradiation, 2),1952 power_ratio: roundfunction((activepower * 100) / (1000 * capacity), 2),1953 };1954 };1955 const { siteid, time, date } = req.query;1956 const [capacity] = await Promise.all([1957 axios1958 .get(`http://localhost:3002/entity/get?`, {1959 params: {1960 id: siteid,1961 },1962 })1963 .then((response) => response.data.data.Capacity),1964 ]);1965 const [firstResponse] = await Promise.all([1966 axios1967 .get(1968 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=EnergyMeter`1969 )1970 .then((response) => response.data.data),1971 ]);1972 const [secondResponse] = await Promise.all([1973 axios1974 .get(1975 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=WeatherStation`1976 )1977 .then((response) => response.data.data),1978 ]);1979 let thirdResponse = [];1980 let fourthResponse = { Irradiation: [] };1981 let url = [];1982 if (firstResponse.length) {1983 firstResponse.map((item, index) => {1984 url.push(1985 axios1986 .get(`http://localhost:3002/entity/get/records`, {1987 params: {1988 id: item.id,1989 attrs: "EnergyMeterProduction,ActivePower",1990 interval: time,1991 filter: "first,last",1992 date: date,1993 },1994 })1995 .then((response) => response.data.data)1996 );1997 });1998 thirdResponse = await Promise.all(url);1999 }2000 if (secondResponse.length) {2001 [fourthResponse] = await Promise.all([2002 axios2003 .get(`http://localhost:3002/entity/get/records`, {2004 params: {2005 id: secondResponse[0].id,2006 attrs: "Irradiation",2007 interval: time,2008 filter: "first,last",2009 date: date,2010 },2011 })2012 .then((response) => response.data.data),2013 ]);2014 }2015 let objdata = handleData(thirdResponse, fourthResponse);2016 return res.send(objdata);2017};2018exports.getDataFleetviewMap = async (req, res) => {2019 const handleProduction = (data) => {2020 let sum = null;2021 data.map((item) => {2022 if (2023 item.EnergyMeterProduction !== null &&2024 item.EnergyMeterProduction.length !== 02025 ) {2026 sum = sum + item.EnergyMeterProduction[0].last.v;2027 }2028 });2029 return sum;2030 };2031 const handleActivePower = (data) => {2032 let sum = null;2033 data.map((item) => {2034 if (item.ActivePower !== null && item.ActivePower.length !== 0) {2035 sum = sum + item.ActivePower[0].last.v;2036 }2037 });2038 return sum;2039 };2040 const handleGHI = (data) => {2041 let result = null;2042 data.map((item) => {2043 if (item.GHI !== null && item.GHI.length !== 0) {2044 result = item.GHI[0].last.v;2045 }2046 });2047 return result;2048 };2049 const { siteids, time, date } = req.query;2050 const entitiesget = await Promise.all(2051 siteids.map((item, index) =>2052 axios2053 .get(`http://localhost:3002/entity/get?id=${item}`)2054 .then((response) => response.data.data)2055 )2056 );2057 let url1 = [];2058 entitiesget.map((item, index) => {2059 url1.push(2060 axios2061 .get(2062 `http://localhost:3002/entity/get?ancestor=${item.id}&kind=EnergyMeter`2063 )2064 .then((response) => response.data.data)2065 );2066 });2067 const firstResponse = await Promise.all(url1);2068 let url2 = [];2069 entitiesget.map((item, index) => {2070 url2.push(2071 axios2072 .get(2073 `http://localhost:3002/entity/get?ancestor=${item.id}&kind=WeatherStation`2074 )2075 .then((response) => response.data.data)2076 );2077 });2078 const secondResponse = await Promise.all(url2);2079 let productiondata = [];2080 let activepowerdata = [];2081 let GHIdata = [];2082 if (firstResponse.length) {2083 for (let i = 0; i < firstResponse.length; i++) {2084 if (firstResponse[i].length) {2085 let a = [];2086 firstResponse[i].map((item1) => {2087 a.push(2088 axios2089 .get(`http://localhost:3002/entity/get/records`, {2090 params: {2091 id: item1.id,2092 attrs: "EnergyMeterProduction,ActivePower",2093 interval: time,2094 filter: "first,last",2095 date: date,2096 },2097 })2098 .then((response) => response.data.data)2099 );2100 });2101 const responseitem = await Promise.all(a);2102 productiondata.push(roundfunction(handleProduction(responseitem), 2));2103 activepowerdata.push(roundfunction(handleActivePower(responseitem), 2));2104 } else {2105 productiondata.push(handleProduction([]));2106 activepowerdata.push(handleActivePower([]));2107 }2108 }2109 }2110 if (secondResponse.length) {2111 for (let i = 0; i < secondResponse.length; i++) {2112 if (secondResponse[i].length) {2113 let a = [];2114 secondResponse[i].map((item1) => {2115 a.push(2116 axios2117 .get(`http://localhost:3002/entity/get/records`, {2118 params: {2119 id: item1.id,2120 attrs: "GHI",2121 interval: time,2122 filter: "first,last",2123 date: date,2124 },2125 })2126 .then((response) => response.data.data)2127 );2128 });2129 const responseitem = await Promise.all(a);2130 GHIdata.push(roundfunction(handleGHI(responseitem), 2));2131 } else {2132 GHIdata.push(handleGHI([]));2133 }2134 }2135 }2136 let objdata = [];2137 entitiesget.map((item, index) => {2138 objdata.push({2139 sitename: item.name,2140 production: productiondata[index],2141 activepower: activepowerdata[index],2142 ghi: GHIdata[index],2143 });2144 });2145 return res.send(objdata);2146};2147exports.getDataTopologyAnalysisInfor = async (req, res) => {2148 const handleProduction = (data) => {2149 let sum = null;2150 data.map((item) => {2151 if (2152 item.EnergyMeterProduction !== null &&2153 item.EnergyMeterProduction.length !== 02154 ) {2155 sum =2156 sum +2157 item.EnergyMeterProduction[0].last.v -2158 item.EnergyMeterProduction[0].first.v;2159 }2160 });2161 return sum;2162 };2163 const handleActivePower = (data) => {2164 let sum = null;2165 data.map((item) => {2166 if (item.ActivePower !== null && item.ActivePower.length !== 0) {2167 sum = sum + item.ActivePower[0].last.v;2168 }2169 });2170 return sum;2171 };2172 const handleGHI = (data) => {2173 if (data.GHI !== null && data.GHI.length !== 0) {2174 return data.GHI[0].last.v;2175 } else {2176 return null;2177 }2178 };2179 const handleData = (data1, data2) => {2180 let production = handleProduction(data1);2181 let activepower = handleActivePower(data1);2182 let ghi = handleGHI(data2);2183 return {2184 ghi: roundfunction(ghi, 2),2185 activepower: roundfunction(activepower, 2),2186 yield: roundfunction(production / (1000 * capacity), 2),2187 };2188 };2189 const { siteid, time, date } = req.query;2190 const [capacity] = await Promise.all([2191 axios2192 .get(`http://localhost:3002/entity/get?`, {2193 params: {2194 id: siteid,2195 },2196 })2197 .then((response) => response.data.data.Capacity),2198 ]);2199 const [firstResponse] = await Promise.all([2200 axios2201 .get(2202 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=EnergyMeter`2203 )2204 .then((response) => response.data.data),2205 ]);2206 const [secondResponse] = await Promise.all([2207 axios2208 .get(2209 `http://localhost:3002/entity/get?ancestor=${siteid}&kind=WeatherStation`2210 )2211 .then((response) => response.data.data),2212 ]);2213 let thirdResponse = [];2214 let fourthResponse = { GHI: [] };2215 if (firstResponse.length) {2216 let url = [];2217 firstResponse.map((item, index) => {2218 url.push(2219 axios2220 .get(`http://localhost:3002/entity/get/records`, {2221 params: {2222 id: item.id,2223 attrs: "EnergyMeterProduction,ActivePower",2224 interval: time,2225 filter: "first,last",2226 date: date,2227 },2228 })2229 .then((response) => response.data.data)2230 );2231 });2232 thirdResponse = await Promise.all(url);2233 }2234 if (secondResponse.length) {2235 [fourthResponse] = await Promise.all([2236 axios2237 .get(`http://localhost:3002/entity/get/records`, {2238 params: {2239 id: secondResponse[0].id,2240 attrs: "GHI",2241 interval: time,2242 filter: "first,last",2243 date: date,2244 },2245 })2246 .then((response) => response.data.data),2247 ]);2248 }2249 let objdata = handleData(thirdResponse, fourthResponse);2250 return res.send(objdata);2251};2252exports.getDataTopologyAnalysisStringState = async (req, res) => {2253 const handleStringCurrent = (data) => {2254 let array = [];2255 for (let i = 1; i <= 20; i++) {2256 let key = "InverterStringCurrent" + i.toString();2257 if (data[`${key}`] !== null) {2258 if (data[`${key}`].length !== 0) {2259 array.push(roundfunction(data[`${key}`][0].last.v, 2));2260 } else {2261 array.push(null);2262 }2263 } else {2264 array.push(false);2265 }2266 }2267 return array;2268 };2269 const { siteid, time, date } = req.query;2270 const [firstResponse] = await Promise.all([2271 axios2272 .get(`http://localhost:3002/entity/get?ancestor=${siteid}&kind=Inverter`)2273 .then((response) => response.data.data),2274 ]);2275 url = [];2276 firstResponse.map((item, index) => {2277 url.push(2278 axios2279 .get(`http://localhost:3002/entity/get/records`, {2280 params: {2281 id: item.id,2282 attrs:2283 "InverterProduction,InverterActivePower,InverterInputPower,InverterEfficiency,InverterIrradiation,InverterInternalTemperature,InverterStringCurrent,InverterStringCurrent1,InverterStringCurrent2,InverterStringCurrent3,InverterStringCurrent4,InverterStringCurrent5,InverterStringCurrent6,InverterStringCurrent7,InverterStringCurrent8,InverterStringCurrent9,InverterStringCurrent10,InverterStringCurrent11,InverterStringCurrent12,InverterStringCurrent13,InverterStringCurrent14,InverterStringCurrent15,InverterStringCurrent16,InverterStringCurrent17,InverterStringCurrent18,InverterStringCurrent19,InverterStringCurrent20,InverterOperationState",2284 interval: time,2285 filter: "first,last",2286 date: date,2287 },2288 })2289 .then((response) => response.data.data)2290 );2291 });2292 const secondResponse = await Promise.all(url);2293 let stringcurrent = [];2294 firstResponse.map((item, index) => {2295 let a = handleStringCurrent(secondResponse[index]);2296 stringcurrent.push(a);2297 });2298 let a = [];2299 firstResponse.map((item, index) => {2300 a.push({2301 name: item.name,2302 yield:2303 secondResponse[index].InverterProduction !== null &&2304 secondResponse[index].InverterProduction.length !== 02305 ? roundfunction(2306 (secondResponse[index].InverterProduction[0].last.v -2307 secondResponse[index].InverterProduction[0].first.v) /2308 item.Capacity,2309 22310 )2311 : "--",2312 efficiency:2313 secondResponse[index].InverterEfficiency !== null &&2314 secondResponse[index].InverterEfficiency.length !== 02315 ? roundfunction(secondResponse[index].InverterEfficiency[0].last.v, 2)2316 : "--",2317 internal_temp:2318 secondResponse[index].InverterInternalTemperature !== null &&2319 secondResponse[index].InverterInternalTemperature.length !== 02320 ? roundfunction(2321 secondResponse[index].InverterInternalTemperature[0].last.v,2322 22323 )2324 : "--",2325 string_current: stringcurrent[index],2326 });2327 });2328 res.send(a);...

Full Screen

Full Screen

Weather.js

Source:Weather.js Github

copy

Full Screen

1import React, { Component } from 'react'2import kisobran from '../img/rainbow.jpg'3import {Container,Row,Col,Form, FormGroup, FormControl ,Button,Card,Navbar,Nav} from 'react-bootstrap';4import axios from 'axios';5import weatherStyle from '../Styles/Weather.module.css'6const x =['novi sad','maribor','podgorica','belgrad']7const t =Math.floor(Math.random()*x.length)8export default class Weather extends Component {9 constructor(){10 super()11 this.state={12 city:x[t],13 temp:[],14 description:[],15 nowImage:[],16 wind:[],17 humidity:[],18 fistDayDate:[],19 secondDayDate:[],20 threedDayDate:[],21 fourDayDate:[],22 fiveDayDate:[],23 fistDayImage:[],24 secondDayImage:[],25 threedDayImage:[],26 fourDayImage:[],27 fiveDayImage:[],28 fistDayMaxTemp:[],29 secondDayMaxTemp:[],30 thredDayMaxTemp:[],31 fourDayMaxTemp:[],32 fiveDayMaxTemp:[],33 fistDayPressure:[],34 secondDayPressure:[],35 thredDayPressure:[],36 fourDayPressure:[],37 fiveDayPressure:[],38 fistDayDescripton:[],39 secondDayDescripton:[],40 thredDayDescripton:[],41 fourDayDescripton:[],42 fiveDayDescripton:[],43 fistDayWind:[],44 secondDayWind:[],45 threedDayWind:[],46 fourDayWind:[],47 fiveDayWind:[],48 userInput:[]49 50 }51 this.getUserInput=this.getUserInput.bind(this)52 this.sendUserCity=this.sendUserCity.bind(this)53 54 55 56 57 }58async componentDidMount(){59 const inputClassValue = document.querySelector('.inputClassValue')60 axios.all([axios.get(`https://api.openweathermap.org/data/2.5/weather?q=${this.state.city}&units=metric&appid=${process.env.REACT_APP_WEATHER_KEY}`),61 axios.get(`https://api.openweathermap.org/data/2.5/forecast?q=${this.state.city}&units=metric&appid=${process.env.REACT_APP_WEATHER_KEY}`)])62 63 .then(axios.spread((firstResponse, secondResponse) => { 64 // console.log(firstResponse.data,secondResponse.data);65 inputClassValue.value=''66 setTimeout(()=>{67 this.setState({68 fistDayDate:secondResponse.data.list[6].dt_txt,69 secondDayDate:secondResponse.data.list[14].dt_txt,70 threedDayDate:secondResponse.data.list[22].dt_txt,71 fourDayDate:secondResponse.data.list[30].dt_txt,72 fiveDayDate:secondResponse.data.list[38].dt_txt,73 fistDayImage:`https://openweathermap.org/img/w/${secondResponse.data.list[6].weather[0].icon}.png`,74 secondDayImage:`https://openweathermap.org/img/w/${secondResponse.data.list[14].weather[0].icon}.png`,75 threedDayImage:`https://openweathermap.org/img/w/${secondResponse.data.list[22].weather[0].icon}.png`,76 fourDayImage:`https://openweathermap.org/img/w/${secondResponse.data.list[30].weather[0].icon}.png`,77 fiveDayImage:`https://openweathermap.org/img/w/${secondResponse.data.list[38].weather[0].icon}.png`,78 79 fistDayMaxTemp:secondResponse.data.list[6].main.temp_max,80 secondDayMaxTemp:secondResponse.data.list[14].main.temp_max,81 thredDayMaxTemp:secondResponse.data.list[22].main.temp_max,82 fourDayMaxTemp:secondResponse.data.list[30].main.temp_max,83 fiveDayMaxTemp:secondResponse.data.list[38].main.temp_max,84 fistDayPressure:secondResponse.data.list[6].main.pressure,85 secondDayPressure:secondResponse.data.list[14].main.pressure,86 thredDayPressure:secondResponse.data.list[22].main.pressure,87 fourDayPressure:secondResponse.data.list[30].main.pressure,88 fiveDayPressure:secondResponse.data.list[38].main.pressure,89 fistDayDescripton:secondResponse.data.list[6].weather[0].description,90 secondDayDescripton:secondResponse.data.list[14].weather[0].description,91 thredDayDescripton:secondResponse.data.list[22].weather[0].description,92 fourDayDescripton:secondResponse.data.list[30].weather[0].description,93 fiveDayDescripton:secondResponse.data.list[38].weather[0].description,94 fistDayWind:secondResponse.data.list[6].wind.speed,95 secondDayWind:secondResponse.data.list[14].wind.speed,96 threedDayWind:secondResponse.data.list[22].wind.speed,97 fourDayWind:secondResponse.data.list[30].wind.speed,98 fiveDayWind:secondResponse.data.list[38].wind.speed,99 100 101 })102 },100)103 this.setState({104 city:firstResponse.data.name,105 temp:firstResponse.data.main.temp,106 description:firstResponse.data.weather[0].description,107 nowImage:firstResponse.data.weather[0].icon,108 wind:firstResponse.data.wind.speed,109 humidity:firstResponse.data.main.humidity110 111 112 });113 114 }))115 .catch(error => console.log(error));116 117}118getUserInput(e){119 this.setState({120 userInput:e.target.value121 })122 123}124sendUserCity(g){125 g.preventDefault()126 const inputClassValue = document.querySelector('.inputClassValue')127 axios.all([axios.get(`https://api.openweathermap.org/data/2.5/weather?q=${this.state.userInput}&units=metric&appid=${process.env.REACT_APP_WEATHER_KEY}`),128 axios.get(`https://api.openweathermap.org/data/2.5/forecast?q=${this.state.userInput}&units=metric&appid=${process.env.REACT_APP_WEATHER_KEY}`)])129.then(axios.spread((firstResponse, secondResponse) => { 130// console.log(firstResponse.data,secondResponse.data);131 inputClassValue.value=''132setTimeout(()=>{133this.setState({134 fistDayDate:secondResponse.data.list[6].dt_txt,135 secondDayDate:secondResponse.data.list[14].dt_txt,136 threedDayDate:secondResponse.data.list[22].dt_txt,137 fourDayDate:secondResponse.data.list[30].dt_txt,138 fiveDayDate:secondResponse.data.list[38].dt_txt,139 fistDayImage:`https://openweathermap.org/img/w/${secondResponse.data.list[6].weather[0].icon}.png`,140 secondDayImage:`https://openweathermap.org/img/w/${secondResponse.data.list[14].weather[0].icon}.png`,141 threedDayImage:`https://openweathermap.org/img/w/${secondResponse.data.list[22].weather[0].icon}.png`,142 fourDayImage:`https://openweathermap.org/img/w/${secondResponse.data.list[30].weather[0].icon}.png`,143 fiveDayImage:`https://openweathermap.org/img/w/${secondResponse.data.list[38].weather[0].icon}.png`,144 145 fistDayMaxTemp:secondResponse.data.list[6].main.temp_max,146 secondDayMaxTemp:secondResponse.data.list[14].main.temp_max,147 thredDayMaxTemp:secondResponse.data.list[22].main.temp_max,148 fourDayMaxTemp:secondResponse.data.list[30].main.temp_max,149 fiveDayMaxTemp:secondResponse.data.list[38].main.temp_max,150 fistDayPressure:secondResponse.data.list[6].main.pressure,151 secondDayPressure:secondResponse.data.list[14].main.pressure,152 thredDayPressure:secondResponse.data.list[22].main.pressure,153 fourDayPressure:secondResponse.data.list[30].main.pressure,154 fiveDayPressure:secondResponse.data.list[38].main.pressure,155 fistDayDescripton:secondResponse.data.list[6].weather[0].description,156 secondDayDescripton:secondResponse.data.list[14].weather[0].description,157 thredDayDescripton:secondResponse.data.list[22].weather[0].description,158 fourDayDescripton:secondResponse.data.list[30].weather[0].description,159 fiveDayDescripton:secondResponse.data.list[38].weather[0].description,160 fistDayWind:secondResponse.data.list[6].wind.speed,161 secondDayWind:secondResponse.data.list[14].wind.speed,162 threedDayWind:secondResponse.data.list[22].wind.speed,163 fourDayWind:secondResponse.data.list[30].wind.speed,164 fiveDayWind:secondResponse.data.list[38].wind.speed,165 166})167},100)168this.setState({169 city:firstResponse.data.name,170 temp:firstResponse.data.main.temp,171 description:firstResponse.data.weather[0].description,172 nowImage:firstResponse.data.weather[0].icon,173 wind:firstResponse.data.wind.speed,174 humidity:firstResponse.data.main.humidity175});176}))177.catch(error=>{ console.log(error)178 window.location='/'179})180}181 render() {182 183 184 return ( 185 186 <div className={weatherStyle.mainWeatherDiv}>187 <img src={kisobran} alt="adada" className={weatherStyle.slika} /> 188 189 190 191 <div className={weatherStyle.firstDiv}>192 <h5 className="text-light">Weather App</h5>193 194 195 <Form inline className="" onSubmit={this.sendUserCity}>196 <FormControl size='sm' type="text"className="inputClassValue" onChange={this.getUserInput}></FormControl>197 <Button size='sm' className="inputClassValue" type='submit'>Search</Button>198 </Form>199 200 </div>201 <div className={weatherStyle.secondDiv}>202 <h2 className="text-light">{this.state.city.slice(0,1).toString().toUpperCase()+this.state.city.slice(1,15)}</h2>203 <h1 className="text-light">{Math.floor(this.state.temp)+ '\xB0'}</h1>204 <h3 className="text-light">{this.state.description.slice(0,1).toString().toUpperCase()+this.state.description.slice(1,15)}</h3>205 <h4 className="text-light">Wind:{this.state.wind} m/s</h4>206 <h3 className="text-light">Humidity:{this.state.humidity} %</h3>207 208 </div>209 210 <div className={weatherStyle.threedDiv}>211 <div className={weatherStyle.threedDiv_items}>212 <h4>{this.state.fistDayDate.slice(8,10)}.{this.state.fistDayDate.slice(5,7)} | {this.state.secondDayDate.slice(0,4)}</h4>213 <h4>{this.state.fistDayDate.slice(10,16)}</h4>214 <h5><img src={this.state.fistDayImage} /></h5>215 <h3>{Math.floor(this.state.fistDayMaxTemp)+'\xB0'}</h3>216 <h5>{this.state.fistDayDescripton}</h5>217 <h5>Wind:{this.state.fistDayWind} m/s</h5>218 <h5>Press:{this.state.fistDayPressure} mb </h5>219 220 </div>221 <div className={weatherStyle.threedDiv_items}>222 <h4>{this.state.secondDayDate.slice(8,10)}.{this.state.secondDayDate.slice(5,7)} | {this.state.secondDayDate.slice(0,4)}</h4>223 <h4>{this.state.secondDayDate.slice(10,16)}</h4>224 <h5><img src={this.state.secondDayImage} /></h5>225 <h3>{Math.floor(this.state.secondDayMaxTemp)+'\xB0'}</h3>226 <h5>{this.state.fistDayDescripton}</h5>227 <h5>Wind:{this.state.fistDayWind} m/s</h5>228 <h5>Press:{this.state.secondDayPressure} mb </h5>229 </div>230 <div className={weatherStyle.threedDiv_items}>231 <h4>{this.state.threedDayDate.slice(8,10)}.{this.state.threedDayDate.slice(5,7)} | {this.state.secondDayDate.slice(0,4)}</h4>232 <h4>{this.state.threedDayDate.slice(10,16)}</h4>233 <h5><img src={this.state.threedDayImage} /></h5>234 <h3>{Math.floor(this.state.thredDayMaxTemp)+'\xB0'}</h3>235 <h5>{this.state.thredDayDescripton}</h5>236 <h5>Wind:{this.state.threedDayWind} m/s</h5>237 <h5>Press:{this.state.thredDayPressure} mb</h5>238 </div>239 <div className={weatherStyle.threedDiv_items}>240 <h4>{this.state.fourDayDate.slice(8,10)}.{this.state.fourDayDate.slice(5,7)} | {this.state.secondDayDate.slice(0,4)}</h4>241 <h4>{this.state.fourDayDate.slice(10,16)}</h4>242 <h5><img src={this.state.fourDayImage} /></h5>243 <h3>{Math.floor(this.state.fourDayMaxTemp)+'\xB0'}</h3>244 <h5>{this.state.fourDayDescripton}</h5>245 <h5>Wind:{this.state.fourDayWind} m/s</h5>246 <h5>Press:{this.state.fourDayPressure} mb</h5>247 </div>248 249 <div className={weatherStyle.threedDiv_items}>250 <h4>{this.state.fiveDayDate.slice(8,10)}.{this.state.fiveDayDate.slice(5,7)} | {this.state.secondDayDate.slice(0,4)}</h4>251 <h4>{this.state.fiveDayDate.slice(10,16)}</h4>252 <h5><img src={this.state.fiveDayImage} /></h5>253 <h3>{Math.floor(this.state.fiveDayMaxTemp)+'\xB0'}</h3>254 <h5>{this.state.fiveDayDescripton}</h5>255 <h5>Wind:{this.state.fiveDayWind} m/s</h5>256 <h5>Press:{this.state.fiveDayPressure} mb</h5>257 258 </div>259 </div>260 <div className={weatherStyle.prazanDiv}>261 </div>262 263 </div>264 265 266 267 )268 }...

Full Screen

Full Screen

responsesAreSame.ts

Source:responsesAreSame.ts Github

copy

Full Screen

1/*2 Copyright 2018 Google LLC3 Use of this source code is governed by an MIT-style4 license that can be found in the LICENSE file or at5 https://opensource.org/licenses/MIT.6*/7import {WorkboxError} from 'workbox-core/_private/WorkboxError.js';8import {logger} from 'workbox-core/_private/logger.js';9import './_version.js';10/**11 * Given two `Response's`, compares several header values to see if they are12 * the same or not.13 *14 * @param {Response} firstResponse15 * @param {Response} secondResponse16 * @param {Array<string>} headersToCheck17 * @return {boolean}18 *19 * @memberof module:workbox-broadcast-update20 */21const responsesAreSame = (22 firstResponse: Response,23 secondResponse: Response,24 headersToCheck: string[],25) => {26 if (process.env.NODE_ENV !== 'production') {27 if (!(firstResponse instanceof Response &&28 secondResponse instanceof Response)) {29 throw new WorkboxError('invalid-responses-are-same-args');30 }31 }32 const atLeastOneHeaderAvailable = headersToCheck.some((header) => {33 return firstResponse.headers.has(header) &&34 secondResponse.headers.has(header);35 });36 if (!atLeastOneHeaderAvailable) {37 if (process.env.NODE_ENV !== 'production') {38 logger.warn(`Unable to determine where the response has been updated ` +39 `because none of the headers that would be checked are present.`);40 logger.debug(`Attempting to compare the following: `,41 firstResponse, secondResponse, headersToCheck);42 }43 // Just return true, indicating the that responses are the same, since we44 // can't determine otherwise.45 return true;46 }47 return headersToCheck.every((header) => {48 const headerStateComparison = firstResponse.headers.has(header) ===49 secondResponse.headers.has(header);50 const headerValueComparison = firstResponse.headers.get(header) ===51 secondResponse.headers.get(header);52 return headerStateComparison && headerValueComparison;53 });54};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import { storiesOf } from '@storybook/react';3import { action } from '@storybook/addon-actions';4import { linkTo } from '@storybook/addon-links';5import Button from './Button';6import Welcome from './Welcome';7storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);8storiesOf('Button', module)9 .add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>)10 .add('with some emoji', () => (11 <Button onClick={action('clicked')}>๐Ÿ˜€ ๐Ÿ˜Ž ๐Ÿ‘ ๐Ÿ’ฏ</Button>12 ));13import { configure } from '@storybook/react';14configure(require.context('../src', true, /\.stories\.js$/), module);15import '@storybook/addon-actions/register';16import '@storybook/addon-links/register';17module.exports = ({ config }) => {18 config.module.rules.push({19 test: /\.(ts|tsx)$/,20 loader: require.resolve('awesome-typescript-loader'),21 });22 config.resolve.extensions.push('.ts', '.tsx');23 return config;24};25import React from 'react';26import { addDecorator } from '@storybook/react';27import { withInfo } from '@storybook/addon-info';28import { withKnobs } from '@storybook/addon-knobs';29addDecorator(withInfo);30addDecorator(withKnobs);31import { addons } from '@storybook/addons';32addons.setConfig({33});34{35 "scripts": {36 },37 "devDependencies": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const secondResponse = require('storybook-root').secondResponse;2const firstResponse = require('storybook-root').firstResponse;3const thirdResponse = require('storybook-root').thirdResponse;4const fourthResponse = require('storybook-root').fourthResponse;5const fifthResponse = require('storybook-root').fifthResponse;6const sixthResponse = require('storybook-root').sixthResponse;7const seventhResponse = require('storybook-root').seventhResponse;8const eighthResponse = require('storybook-root').eighthResponse;9const ninthResponse = require('storybook-root').ninthResponse;10const tenthResponse = require('storybook-root').tenthResponse;11const eleventhResponse = require('storybook-root').eleventhResponse;12const twelfthResponse = require('storybook-root').twelfthResponse;13const thirteenthResponse = require('storybook-root').thirteenthResponse;14const fourteenthResponse = require('storybook-root').fourteenthResponse;15const fifteenthResponse = require('storybook-root').fifteenthResponse;16const sixteenthResponse = require('storybook-root').sixteenthResponse;17const seventeenthResponse = require('storybook-root').seventeenthResponse;18const eighteenthResponse = require('storybook-root').eighteenthResponse;19const nineteenthResponse = require('storybook-root').nineteenthResponse;

Full Screen

Using AI Code Generation

copy

Full Screen

1import { secondResponse } from 'storybook-root';2import { secondResponse } from 'storybook-root';3import { secondResponse } from 'storybook-root';4import { secondResponse } from 'storybook-root';5import { secondResponse } from 'storybook-root';6import { secondResponse } from 'storybook-root';7import { secondResponse } from 'storybook-root';8import { secondResponse } from 'storybook-root';9import { secondResponse } from 'storybook-root';10import { secondResponse } from 'storybook-root';11import { secondResponse } from 'storybook-root';12import { secondResponse } from 'storybook-root';13import { secondResponse } from 'storybook-root';14import { secondResponse } from 'storybook-root';15import { secondResponse } from 'storybook-root';16import { secondResponse } from 'storybook-root';17import { secondResponse } from 'storybook-root';18import { secondResponse } from 'storybook-root';19import { secondResponse } from 'storybook-root';20import { secondResponse } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1import {secondResponse} from 'storybook-root'2import {thirdResponse} from 'storybook-root'3import {fourthResponse} from 'storybook-root'4import {fifthResponse} from 'storybook-root'5import {sixthResponse} from 'storybook-root'6import {seventhResponse} from 'storybook-root'7import {eighthResponse} from 'storybook-root'8import {ninthResponse} from 'storybook-root'9import {tenthResponse} from 'storybook-root'10import {eleventhResponse} from 'storybook-root'11import {twelfthResponse} from 'storybook-root'12import {thirteenthResponse} from 'storybook-root'13import {fourteenthResponse} from 'storybook-root'14import {fifteenthResponse} from 'storybook-root'15import {sixteenthResponse} from 'storybook-root'16import {seventeenthResponse} from 'storybook-root'17import {eighteenthResponse} from 'storybook-root'18import {nineteenthResponse} from 'storybook-root'19import {twentiethResponse} from 'storybook-root'20import {twentyFirstResponse} from 'storybook-root'21import {twentySecondResponse} from 'storybook-root'22import {twentyThirdResponse} from 'storybook-root'

Full Screen

Using AI Code Generation

copy

Full Screen

1import { secondResponse } from 'storybook-root'2import { storiesOf } from '@storybook/react'3import React from 'react'4import { action } from '@storybook/addon-actions'5import Button from './Button'6storiesOf('Button', module)7 .add('with text', () => (8 <Button onClick={action('clicked')}>Hello Button</Button>9 .add('with some emoji', () => (10 <Button onClick={action('clicked')}>๐Ÿ˜€ ๐Ÿ˜Ž ๐Ÿ‘ ๐Ÿ’ฏ</Button>11 .add('with secondResponse', () => (12 <Button onClick={action('clicked')}>{secondResponse()}</Button>13import React from 'react'14import PropTypes from 'prop-types'15const Button = ({ onClick, children }) => (16 <button onClick={onClick}>17 {children}18Button.propTypes = {19}20export default function secondResponse() {21}22export default function firstResponse() {23}24import firstResponse from './firstResponse'25import secondResponse from './secondResponse'26export { secondResponse }27import { configure } from '@storybook/react'28function loadStories() {29 require('../test.js')30}31configure(loadStories, module)32const path = require('path')33module.exports = (baseConfig, env, config) => {34 config.resolve.modules.push(path.resolve(__dirname, '../'))35}36{37 "scripts": {38 },39 "devDependencies": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require('storybook-root');2const secondResponse = storybookRoot.secondResponse;3console.log(secondResponse);4const firstResponse = require('first-module');5const secondResponse = require('second-module');6module.exports = {7};8module.exports = 'first response';9module.exports = 'second response';10const storybookRoot = require('storybook-root');11const secondResponse = storybookRoot.secondResponse;12console.log(secondResponse);13const storybookRoot = require('storybook-root');14const secondResponse = storybookRoot.secondResponse;15console.log(secondResponse);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { secondResponse } from "storybook-root"2secondResponse()3export const secondResponse = () => {4 console.log("second response")5}6import { firstResponse } from "storybook-root"7firstResponse()8export const firstResponse = () => {9 console.log("first response")10}11{12 {13 "alias": {14 }15 }16}17module.exports = (baseConfig, env, defaultConfig) => {18 defaultConfig.module.rules.push({19 test: /\.(js|jsx)$/,20 loader: require.resolve("babel-loader"),21 options: {22 presets: [require.resolve("babel-preset-react-app")],23 require.resolve("babel-plugin-module-resolver"),24 require.resolve("babel-plugin-styled-components")25 }26 })27}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { secondResponse } from "storybook-root";2const secondResponse = secondResponse();3console.log(secondResponse);4import { thirdResponse } from "storybook-root";5const thirdResponse = thirdResponse();6console.log(thirdResponse);7import { fourthResponse } from "storybook-root";8const fourthResponse = fourthResponse();9console.log(fourthResponse);10import { fifthResponse } from "storybook-root";11const fifthResponse = fifthResponse();12console.log(fifthResponse);13import { sixthResponse } from "storybook-root";14const sixthResponse = sixthResponse();15console.log(sixthResponse);16import { seventhResponse } from "storybook-root";17const seventhResponse = seventhResponse();18console.log(seventhResponse);19import { eighthResponse } from "storybook-root";20const eighthResponse = eighthResponse();21console.log(eighthResponse);22import { ninthResponse } from "storybook-root";23const ninthResponse = ninthResponse();24console.log(ninthResponse);25import { tenthResponse } from "storybook-root";26const tenthResponse = tenthResponse();27console.log(tenthResponse);28import { eleventhResponse } from "storybook-root";29const eleventhResponse = eleventhResponse();30console.log(eleventhResponse);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful