You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@alexander0042 Was working on getting the minutely summary setup and was able to get something working:
Minutely Summary
fromjavascriptimportrequiredefcalculate_text(precipIntensity, prepIntensityUnit, precipType):
""" Calculates the textual precipitation text for the week. Parameters: - avgIntensity (float): The average precipitation intensity for the week - intensityUnit (int): The conversion factor for the precipitation intensity - precipType (str): The type of precipitation for the week Returns: - cSummary (str): The textual summary of conditions (very-light-rain, medium-sleet, etc.). """possibleText=""ifprecipIntensity< (0.02*prepIntensityUnit):
possibleText="possible-"ifprecipType=="rain":
ifprecipIntensity< (0.4*prepIntensityUnit):
cSummary=possibleText+"very-light-rain"elifprecipIntensity>= (0.4*prepIntensityUnit) andprecipIntensity< (
2.5*prepIntensityUnit
):
cSummary="light-rain"elifprecipIntensity>= (2.5*prepIntensityUnit) andprecipIntensity< (
10*prepIntensityUnit
):
cSummary="medium-rain"else:
cSummary="heavy-rain"elifprecipType=="snow":
ifprecipIntensity< (0.13*prepIntensityUnit):
cSummary=possibleText+"very-light-snow"elifprecipIntensity>= (0.13*prepIntensityUnit) andprecipIntensity< (
0.83*prepIntensityUnit
):
cSummary="light-snow"elifprecipIntensity>= (0.83*prepIntensityUnit) andprecipIntensity< (
3.33*prepIntensityUnit
):
cSummary="medium-snow"else:
cSummary="heavy-snow"elifprecipType=="sleet":
ifprecipIntensity< (0.4*prepIntensityUnit):
cSummary=possibleText+"very-light-sleet"elifprecipIntensity>= (0.4*prepIntensityUnit) andprecipIntensity< (
2.5*prepIntensityUnit
):
cSummary="light-sleet"elifprecipIntensity>= (2.5*prepIntensityUnit) andprecipIntensity< (
10*prepIntensityUnit
):
cSummary="medium-sleet"else:
cSummary="heavy-sleet"else:
# Because soemtimes there's precipitation not no type use a generic precipitation summaryifprecipIntensity< (0.4*prepIntensityUnit):
cSummary=possibleText+"very-light-precipitation"elifprecipIntensity>= (0.4*prepIntensityUnit) andprecipIntensity< (
2.5*prepIntensityUnit
):
cSummary="light-precipitation"elifprecipIntensity>= (2.5*prepIntensityUnit) andprecipIntensity< (
10*prepIntensityUnit
):
cSummary="medium-precipitation"else:
cSummary="heavy-precipitation"returncSummarydefcalculate_minutely_text(minuteArr, currentText, currentIcon):
""" Calculates the minutely summary given an array of minutes Parameters: - minuteArr (arr): An array of the minutes - currentText (str/arr): The current conditions in translations format - currentIcon (str): The icon representing the current conditions Returns: - cText (arr): The precipitation and temperature summary for the hour. - cIcon (str): The icon representing the conditions for the hour. """# Variables to use in calculating the minutely summarycIcon=NonecText=NonerainStart1=-1rainEnd1=-1rainStart2=-1snowStart1=-1snowEnd1=-1snowStart2=-1sleetStart1=-1sleetEnd1=-1sleetStart2=-1noneStart1=-1noneEnd1=-1noneStart2=-1avgIntensity=0precipMinutes=0rainMaxIntensity=0snowMaxIntensity=0sleetMaxIntensity=0noneMaxIntensity=0precipIntensityUnit=1first_precip="none"# Loop through the minute arrayforidx, minuteinenumerate(minuteArr):
# If there is rain for the current minute in the arrayifminute[1] =="rain"andminute[0] >0:
# Increase the minutes of precipitation, the precipitation unit and average intensityavgIntensity+=minute[0]
precipMinutes+=1precipIntensityUnit=minute[2]
# Set the maxiumum rain intensityifrainMaxIntensity==0:
rainMaxIntensity=minute[0]
elifrainMaxIntensity>0andminute[0] >rainMaxIntensity:
rainMaxIntensity=minute[0]
# Set the first rain first index if not set to the current indexifrainStart1==-1:
rainStart1=idx# If the first rain starting and ending index is already set then set the second starting indexelifrainStart1!=-1andrainEnd1!=-1andrainStart2==-1:
rainStart2=idx# If there is a first snow starting index but no ending index then set that to the current indexifsnowStart1!=-1andsnowStart2==-1andsnowEnd1==-1:
snowEnd1=idx# If there is a first sleet starting index but no ending index then set that to the current indexifsleetStart1!=-1andsleetStart2==-1andsleetEnd1==-1:
sleetEnd1=idx# If there is a first none starting index but no ending index then set that to the current indexifnoneStart1!=-1andnoneStart2==-1andnoneEnd1==-1:
noneEnd1=idx# If there is snow for the current minute in the arrayelifminute[1] =="snow"andminute[0] >0:
# Increase the minutes of precipitation, the precipitation unit and average intensityavgIntensity+=minute[0]
precipMinutes+=1precipIntensityUnit=minute[2]
# Set the maxiumum snow intensityifsnowMaxIntensity==0:
snowMaxIntensity=minute[0]
elifsnowMaxIntensity>0andminute[0] >snowMaxIntensity:
snowMaxIntensity=minute[0]
# Set the first snow first index if not set to the current indexifsnowStart1==-1:
snowStart1=idx# If the first snow starting and ending index is already set then set the second starting indexelifsnowStart1!=-1andsnowEnd1!=-1andsnowStart2==-1:
snowStart2=idx# If there is a first rain starting index but no ending index then set that to the current indexifrainStart1!=-1andrainStart2==-1andrainEnd1==-1:
rainEnd1=idx# If there is a first sleet starting index but no ending index then set that to the current indexifsleetStart1!=-1andsleetStart2==-1andsleetEnd1==-1:
sleetEnd1=idx# If there is a first none starting index but no ending index then set that to the current indexifnoneStart1!=-1andnoneStart2==-1andnoneEnd1==-1:
noneEnd1=idx# If there is sleet for the current minute in the arrayelifminute[1] =="sleet"andminute[0] >0:
# Increase the minutes of precipitation, the precipitation unit and average intensityavgIntensity+=minute[0]
precipMinutes+=1precipIntensityUnit=minute[2]
# Set the maxiumum sleet intensityifsleetMaxIntensity==0:
sleetMaxIntensity=minute[0]
elifsleetMaxIntensity>0andminute[0] >sleetMaxIntensity:
sleetMaxIntensity=minute[0]
# Set the first sleet first index if not set to the current indexifsleetStart1==-1:
sleetStart1=idx# If the first sleet starting and ending index is already set then set the second starting indexelifsleetStart1!=-1andsleetEnd1!=-1andsleetStart2==-1:
sleetStart2=idx# If there is a first rain starting index but no ending index then set that to the current indexifrainStart1!=-1andrainStart2==-1andrainEnd1==-1:
rainEnd1=idx# If there is a first snow starting index but no ending index then set that to the current indexifsnowStart1!=-1andsnowStart2==-1andsnowEnd1==-1:
sleetEnd1=idx# If there is a first none starting index but no ending index then set that to the current indexifnoneStart1!=-1andnoneStart2==-1andnoneEnd1==-1:
noneEnd1=idxelifminute[1] =="none"andminute[0] >0:
# Increase the minutes of precipitation, the precipitation unit and average intensityavgIntensity+=minute[0]
precipMinutes+=1precipIntensityUnit=minute[2]
# Set the none maxiumum precipitation intensityifnoneMaxIntensity==0:
noneMaxIntensity=minute[0]
elifnoneMaxIntensity>0andminute[0] >noneMaxIntensity:
noneMaxIntensity=minute[0]
# Set the first none first index if not set to the current indexifnoneStart1==-1:
noneStart1=idx# If the first none starting and ending index is already set then set the second starting indexelifnoneStart1!=-1andnoneEnd1!=-1andnoneStart2==-1:
noneStart2=idx# If there is a first rain starting index but no ending index then set that to the current indexifrainStart1!=-1andrainStart2==-1andrainEnd1==-1:
rainEnd1=idx# If there is a first snow starting index but no ending index then set that to the current indexifsnowStart1!=-1andsnowStart2==-1andsnowEnd1==-1:
snowEnd1=idx# If there is no precipitation for the current minuteelse:
# If there is a first rain starting index but no ending index then set that to the current indexifrainStart1!=-1andrainStart2==-1andrainEnd1==-1:
rainEnd1=idx# If there is a first snow starting index but no ending index then set that to the current indexifsnowStart1!=-1andsnowStart2==-1andsnowEnd1==-1:
snowEnd1=idx# If there is a first sleet starting index but no ending index then set that to the current indexifsleetStart1!=-1andsnowStart2==-1andsnowEnd1==-1:
sleetEnd1=idx# If there is a first none starting index but no ending index then set that to the current indexifnoneStart1!=-1andnoneStart2==-1andnoneEnd1==-1:
noneEnd1=idx# If there is a first starting index for rain/snow/sleet but no ending index then set it to 60ifrainStart1!=-1andrainEnd1==-1:
rainEnd1=60ifsnowStart1!=-1andsnowEnd1==-1:
snowEnd1=60ifsleetStart1!=-1andsleetEnd1==-1:
sleetEnd1=60ifnoneStart1!=-1andnoneEnd1==-1:
noneEnd1=60# Calculate the average precipitaiton intensityifprecipMinutes>0:
avgIntensity=avgIntensity/precipMinutes# Create an array of the starting times for the precipitationstarts= []
ifsleetStart1>=0:
starts.append(sleetStart1)
ifsnowStart1>=0:
starts.append(snowStart1)
ifrainStart1>=0:
starts.append(rainStart1)
ifnoneStart1>=0:
starts.append(noneStart1)
# If the array has any values check the minimum against the different precipitation start times and set that as the first precipitaionifstarts:
ifsleetStart1==min(starts):
first_precip="sleet"elifsnowStart1==min(starts):
first_precip="snow"elifrainStart1==min(starts):
first_precip="rain"elifnoneStart1==min(starts):
first_precip="none"# If there is no precipitation then set the minutely summary/icon to the current icon/summaryif (
rainStart1==rainEnd1==rainStart2==snowStart1==snowEnd1==snowStart2==sleetStart1==sleetEnd1==sleetStart2==noneStart1==noneEnd1==noneStart2==-1
):
cText= ["sentence", ["for-hour", currentText]]
cIcon=currentIcon# If the current precipitation is sleet and it stops before the end of the hourelifsleetStart1==0andsleetEnd1<60andsleetStart2==-1:
cText= [
"sentence",
[
"stopping-in",
calculate_text(sleetMaxIntensity, precipIntensityUnit, "sleet"),
["minutes", sleetEnd1],
],
]
cIcon="sleet"# If the current precipitation is snow and it stops before the end of the hourelifsnowStart1==0andsnowEnd1<60andsnowStart2==-1:
cText= [
"sentence",
[
"stopping-in",
calculate_text(snowMaxIntensity, precipIntensityUnit, "snow"),
["minutes", snowEnd1],
],
]
cIcon="snow"# If the current precipitation is rain and it stops before the end of the hourelifrainStart1==0andrainEnd1<60andrainStart2==-1:
cText= [
"sentence",
[
"stopping-in",
calculate_text(rainMaxIntensity, precipIntensityUnit, "rain"),
["minutes", rainEnd1],
],
]
cIcon="rain"# If the current precipitation is none and it stops before the end of the hourelifnoneStart1==0andnoneEnd1<60andnoneStart2==-1:
cText= [
"sentence",
[
"stopping-in",
calculate_text(avgIntensity, precipIntensityUnit, "none"),
["minutes", noneEnd1],
],
]
cIcon="rain"# If the current precipitation is sleet and it doesn't stop before the end of the hourelifsleetStart1==0andsleetEnd1==60:
cText= [
"sentence",
[
"for-hour",
calculate_text(sleetMaxIntensity, precipIntensityUnit, "sleet"),
],
]
cIcon="sleet"# If the current precipitation is snow and it doesn't stop before the end of the hourelifsnowStart1==0andsnowEnd1==60:
cText= [
"sentence",
["for-hour", calculate_text(snowMaxIntensity, precipIntensityUnit, "snow")],
]
cIcon="snow"# If the current precipitation is rain and it doesn't stop before the end of the hourelifrainStart1==0andrainEnd1==60:
cText= [
"sentence",
["for-hour", calculate_text(rainMaxIntensity, precipIntensityUnit, "rain")],
]
cIcon="rain"# If the current precipitation is rain and it doesn't stop before the end of the hourelifnoneStart1==0andnoneEnd1==60:
cText= [
"sentence",
["for-hour", calculate_text(avgIntensity, precipIntensityUnit, "none")],
]
cIcon="rain"# If the first precipitation is sleeteliffirst_precip=="sleet":
# If the current precipitation is sleet and it stops before the hour but starts againifsleetStart1==0andsleetEnd1<60andsleetStart2!=-1:
cText= [
"sentence",
[
"stopping-then-starting-later",
calculate_text(sleetMaxIntensity, precipIntensityUnit, "sleet"),
["minutes", sleetEnd1],
["minutes", sleetStart2-sleetEnd1],
],
]
cIcon="sleet"# If sleet starts during the hour and lasts until the end of the hourelifsleetStart1>0andsleetEnd1==60:
cText= [
"sentence",
[
"starting-in",
calculate_text(sleetMaxIntensity, precipIntensityUnit, "sleet"),
["minutes", sleetStart1],
],
]
cIcon="sleet"# If sleet starts during the hour and ends before the end of the hourelifsleetStart1>0andsleetEnd1<60:
cText= [
"sentence",
[
"starting-then-stopping-later",
calculate_text(sleetMaxIntensity, precipIntensityUnit, "sleet"),
["minutes", sleetStart1],
["minutes", sleetEnd1-sleetStart1],
],
]
cIcon="sleet"# If the first precipitation is snoweliffirst_precip=="snow":
# If snow starts during the hour and lasts until the end of the hourifsnowStart1>0andsnowEnd1==60:
cText= [
"sentence",
[
"starting-in",
calculate_text(snowMaxIntensity, precipIntensityUnit, "snow"),
["minutes", snowStart1],
],
]
cIcon="snow"# If snow starts during the hour and ends before the end of the hourelifsnowStart1>0andsnowEnd1<60:
cText= [
"sentence",
[
"starting-then-stopping-later",
calculate_text(snowMaxIntensity, precipIntensityUnit, "snow"),
["minutes", snowStart1],
["minutes", snowEnd1-snowStart1],
],
]
cIcon="snow"# If the current precipitation is snow and it stops before the hour but starts againelifsnowStart1==0andsnowEnd1<60:
cText= [
"sentence",
[
"stopping-then-starting-later",
calculate_text(snowMaxIntensity, precipIntensityUnit, "snow"),
["minutes", snowEnd1],
["minutes", snowStart2-snowEnd1],
],
]
cIcon="snow"# Otherwise use raineliffirst_precip=="rain":
# If rain starts during the hour and lasts until the end of the hourifrainStart1>0andrainEnd1==60:
cText= [
"sentence",
[
"starting-in",
calculate_text(rainMaxIntensity, precipIntensityUnit, "rain"),
["minutes", rainStart1],
],
]
cIcon="rain"# If snow starts during the hour and ends before the end of the hourelifrainStart1>0andrainEnd1<60:
cText= [
"sentence",
[
"starting-then-stopping-later",
calculate_text(rainMaxIntensity, precipIntensityUnit, "rain"),
["minutes", rainStart1],
["minutes", rainEnd1-rainStart1],
],
]
cIcon="rain"# If the current precipitation is rain and it stops before the hour but starts againelifrainStart1==0andrainEnd1<60andrainStart2!=-1:
cText= [
"sentence",
[
"stopping-then-starting-later",
calculate_text(rainMaxIntensity, precipIntensityUnit, "rain"),
["minutes", rainEnd1],
["minutes", rainStart2-rainEnd1],
],
]
cIcon="rain"else:
# If rain starts during the hour and lasts until the end of the hourifnoneStart1>0andnoneEnd1==60:
cText= [
"sentence",
[
"starting-in",
calculate_text(noneMaxIntensity, precipIntensityUnit, "none"),
["minutes", noneStart1],
],
]
cIcon="rain"# If snow starts during the hour and ends before the end of the hourelifnoneStart1>0andnoneEnd1<60:
cText= [
"sentence",
[
"starting-then-stopping-later",
calculate_text(noneMaxIntensity, precipIntensityUnit, "none"),
["minutes", noneStart1],
["minutes", noneEnd1-noneStart1],
],
]
cIcon="rain"# If the current precipitation is rain and it stops before the hour but starts againelifnoneStart1==0andnoneEnd1<60andnoneStart2!=-1:
cText= [
"sentence",
[
"stopping-then-starting-later",
calculate_text(noneMaxIntensity, precipIntensityUnit, "none"),
["minutes", noneEnd1],
["minutes", noneStart2-noneEnd1],
],
]
cIcon="rain"returncText, cIconTranslations=require("./node_modules/translations/index.js")
lang="en"translation=Translations[lang]
iftranslationisNone:
translation=Translations["en"]
currentText="light-rain"currIcon="rain"minuteArr= []
# Intensity, type, unitsminuteArr.append([2.3207, "rain", 1])
minuteArr.append([2.2243, "rain", 1])
minuteArr.append([2.1278, "rain", 1])
minuteArr.append([2.0314, "rain", 1])
minuteArr.append([1.935, "rain", 1])
minuteArr.append([1.8385, "rain", 1])
minuteArr.append([1.7421, "rain", 1])
minuteArr.append([1.6457, "rain", 1])
minuteArr.append([1.5493, "rain", 1])
minuteArr.append([1.4528, "rain", 1])
minuteArr.append([1.3564, "rain", 1])
minuteArr.append([1.26, "rain", 1])
minuteArr.append([1.1635, "rain", 1])
minuteArr.append([1.0735, "rain", 1])
minuteArr.append([1.0253, "rain", 1])
minuteArr.append([0.9771, "rain", 1])
minuteArr.append([0.9289, "rain", 1])
minuteArr.append([0.8807, "rain", 1])
minuteArr.append([0.8325, "rain", 1])
minuteArr.append([0.7843, "rain", 1])
minuteArr.append([0.7361, "rain", 1])
minuteArr.append([0.6878, "rain", 1])
minuteArr.append([0.6396, "rain", 1])
minuteArr.append([0.5914, "rain", 1])
minuteArr.append([0.5432, "rain", 1])
minuteArr.append([0.495, "rain", 1])
minuteArr.append([0.4468, "rain", 1])
minuteArr.append([0.3986, "rain", 1])
minuteArr.append([0.3552, "rain", 1])
minuteArr.append([0.3311, "rain", 1])
minuteArr.append([0.307, "rain", 1])
minuteArr.append([0.2829, "rain", 1])
minuteArr.append([0.2588, "rain", 1])
minuteArr.append([0.2346, "rain", 1])
minuteArr.append([0.2105, "rain", 1])
minuteArr.append([0.1864, "rain", 1])
minuteArr.append([0.1623, "rain", 1])
minuteArr.append([0.1382, "rain", 1])
minuteArr.append([0.1141, "rain", 1])
minuteArr.append([0.09, "rain", 1])
minuteArr.append([0.0659, "rain", 1])
minuteArr.append([0.0418, "rain", 1])
minuteArr.append([0.0177, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
minuteArr.append([0, "rain", 1])
summary_text, cIcon=calculate_minutely_text(minuteArr, currentText, currIcon)
cText=translation.translate(summary_text)
print(cText)
print(cIcon)
It's a bit messy but from my local testing everything seems to work. The one thing I'm not sure about is how to handle multiple precipitation types in an hour. I'm not sure how Dark Sky did it but the logic is show whichever precipitation starts first.
So if there's rain from minute 0 to minute 10 and snow starts at minute 47 then the summary will be: Rain stopping in 10 min. and mentions nothing about snow. Same goes if snow will start in x minutes but switches to sleet x minutes later it will show Snow starting in 29 min., stopping 19 min. later.
Acknowledgements
This issue is related to the self-hosting code and not an API issue.
I have read through the README before opening this issue.
I have written an informative title.
The text was updated successfully, but these errors were encountered:
Describe the issue
@alexander0042 Was working on getting the minutely summary setup and was able to get something working:
Minutely Summary
It's a bit messy but from my local testing everything seems to work. The one thing I'm not sure about is how to handle multiple precipitation types in an hour. I'm not sure how Dark Sky did it but the logic is show whichever precipitation starts first.
So if there's rain from minute 0 to minute 10 and snow starts at minute 47 then the summary will be: Rain stopping in 10 min. and mentions nothing about snow. Same goes if snow will start in x minutes but switches to sleet x minutes later it will show Snow starting in 29 min., stopping 19 min. later.
Acknowledgements
The text was updated successfully, but these errors were encountered: