Skip to content

Commit

Permalink
feat: ForecastNextHour()
Browse files Browse the repository at this point in the history
Update ForecastNextHour.mjs
  • Loading branch information
VirgilClyne committed Oct 5, 2024
1 parent b7e8692 commit 44185a6
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions src/class/ForecastNextHour.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { log } from "../utils/utils.mjs";
export default class ForecastNextHour {
Name = "ForecastNextHour";
Version = "v1.3.2";
Version = "v1.4.1";
Author = "iRingo";

static #Configs = {
Expand Down Expand Up @@ -247,6 +247,7 @@ export default class ForecastNextHour {
static Condition(minutes = []) {
log(`☑️ Condition`, "");
const Conditions = [];
const ConditionCaches = [];
const Condition = {
"beginCondition": "CLEAR",
"endCondition": "CLEAR",
Expand Down Expand Up @@ -283,33 +284,20 @@ export default class ForecastNextHour {
case previousMinute?.condition: // ✅与前次相同
break;
default: // ✅与前次不同
switch (Condition.forecastToken) {
case "CONSTANT":
Condition.endTime = minute.startTime; // ✅更新结束时间
switch (Condition.beginCondition) {
case Condition.endCondition: // ✅与begin相同
Condition.parameters = [];
Conditions.push({ ...Condition });
break;
default: // ✅与begin不同
Condition.endCondition = previousMinute.condition;
Condition.parameters = [{ "date": Condition.endTime, "type": "FIRST_AT" }];
Conditions.push({ ...Condition });
// ✅CONSTANT
Condition.beginCondition = previousMinute.condition;
break;
};
Condition.endCondition = minute.condition;
Condition.startTime = Condition.endTime; // ✅更新开始时间
Condition.parameters = [];
break;
};
Condition.endCondition = previousMinute.condition; // ✅更新结束条件
Condition.endTime = minute.startTime; // ✅更新结束时间
ConditionCaches.push({ ...Condition });
// ✅初始化当前条件
Condition.beginCondition = minute.condition; // ✅更新开始条件
Condition.startTime = Condition.endTime; // ✅更新开始时间
Condition.parameters = [];
break;
};
break;
default: // 与前次不同
switch (Condition.forecastToken) {
case "CLEAR": // ✅当前RAIN
ConditionCaches.length = 0; // ✅清空缓存
// ✅START
Condition.beginCondition = minute.condition;
Condition.endCondition = minute.condition;
Expand All @@ -318,7 +306,6 @@ export default class ForecastNextHour {
Condition.parameters = [{ "date": Condition.endTime, "type": "FIRST_AT" }];
break;
case "CONSTANT": // ✅当前CLEAR
Conditions.length = 0; // ✅清空
// ✅STOP
Condition.beginCondition = minutes[0].condition; // ✅更新结束条件
Condition.endCondition = previousMinute.condition; // ✅更新结束条件
Expand All @@ -328,6 +315,7 @@ export default class ForecastNextHour {
break;
case "START": // ✅当前CLEAR
case "STOP": // ✅当前RAIN
ConditionCaches.length = 0; // ✅清空缓存
// ✅确定上一个条件
switch (Condition.forecastToken) {
case "START":
Expand Down Expand Up @@ -382,9 +370,15 @@ export default class ForecastNextHour {
break;
case "START": // ✅当前RAIN
case "STOP": // ✅当前CLEAR
// ✅确定
// ✅确定上一个条件
ConditionCaches = ConditionCaches.map(conditionCache => {
conditionCache.parameters = [{ "date": Condition.endTime, "type": "FIRST_AT" }];
return conditionCache;
});
Condition.parameters = [{ "date": Condition.endTime, "type": "FIRST_AT" }];
Conditions.push({ ...Condition });
Conditions.push(...ConditionCaches, { ...Condition });
ConditionCaches.length = 0; // ✅清空缓存
// ✅初始化当前条件
switch (Condition.forecastToken) {
case "START":
// ✅补充CONSTANT
Expand Down

0 comments on commit 44185a6

Please sign in to comment.