update recordgenerations

This commit is contained in:
PicelBoi committed 2026-01-19 18:26:04 -05:00
1 parent d3fd21a8bd
commit d4feaa70f1
10 files changed
+493 -491

No files matched your search

+35 -24
View File
@@ -22,36 +22,47 @@ public class AlertDetailsProduct : Base
foreach (var headline in headlines)
{
foreach (Alert alert in headline.ParsedData.alerts)
if (headline.ParsedData.alerts != null)
{
string url =
$"https://api.weather.com/v3/alerts/detail?alertId={alert.detailKey}&format=json&language={Config.config.LocalStarConfig.Language}&apiKey={Config.config.APIConfig.TwcApiKey}";
byte[]? resbyte = await DownloadRecord(url);
if (resbyte == null)
foreach (Alert alert in headline.ParsedData.alerts)
{
continue;
}
string res = Encoding.UTF8.GetString(resbyte);
if (alertsCache.TryGetValue(alert.detailKey, out int expireTime))
{
continue;
}
using (var stream = StreamFromString(res))
{
AlertDetailResponse? response = await JsonSerializer.DeserializeAsync<AlertDetailResponse?>(stream);
if (response != null)
string url =
$"https://api.weather.com/v3/alerts/detail?alertId={alert.detailKey}&format=json&language={Config.config.LocalStarConfig.Language}&apiKey={Config.config.APIConfig.TwcApiKey}";
byte[]? resbyte = await DownloadRecord(url);
if (resbyte == null)
{
results.Add(new GenericResponse<AlertDetailResponse>(headline.Location, res, response));
alertsCache.Set(alert.detailKey, alert.expireTimeUTC);
alertDetailKeys.Add(alert.detailKey);
Log.Debug($"Alert ID {alert.detailKey} cached, expires @ {alert.expireTimeUTC} UTC.");
continue;
}
string res = Encoding.UTF8.GetString(resbyte);
if (alert.detailKey != null)
{
if (alertsCache.TryGetValue(alert.detailKey, out int expireTime))
{
continue;
}
}
using (var stream = StreamFromString(res))
{
AlertDetailResponse? response = await JsonSerializer.DeserializeAsync<AlertDetailResponse?>(stream);
if (response != null)
{
results.Add(new GenericResponse<AlertDetailResponse>(headline.Location, res, response));
if (alert.detailKey != null)
{
alertsCache.Set(alert.detailKey, alert.expireTimeUTC);
alertDetailKeys.Add(alert.detailKey);
Log.Debug($"Alert ID {alert.detailKey} cached, expires @ {alert.expireTimeUTC} UTC.");
}
}
}
}
}
}
return results;
+86 -57
View File
@@ -262,41 +262,53 @@ public class Program
if (mpc != null)
{
foreach (ConfigItem i in mpc.ConfigDef.ConfigItems.ConfigItem)
if (mpc.ConfigDef != null)
{
if (configLocationKeys.Contains(i.Key))
if (mpc.ConfigDef.ConfigItems != null)
{
Log.Debug($"{i.Key}: {i.Value}");
if (string.IsNullOrEmpty(i.Value.ToString()))
if (mpc.ConfigDef.ConfigItems.ConfigItem != null)
{
continue;
}
try
{
if (Regex.IsMatch(i.Value.ToString(), @"^\d\d\d\d\d(?:,\d\d\d\d\d)*$")) {
string[] choppedValues = i.Value.ToString().Split(",");
locations.Add(choppedValues);
}
else
foreach (ConfigItem i in mpc.ConfigDef.ConfigItems.ConfigItem)
{
string[] choppedValues = i.Value.ToString().Split("_");
if (i.Key != null)
{
if (configLocationKeys.Contains(i.Key))
{
Log.Debug($"{i.Key}: {i.Value}");
if (string.IsNullOrEmpty(i.Value))
{
continue;
}
try
{
if (Regex.IsMatch(i.Value.ToString(), @"^\d\d\d\d\d(?:,\d\d\d\d\d)*$")) {
string[] choppedValues = i.Value.ToString().Split(",");
locations.Add(choppedValues);
}
else
{
string[] choppedValues = i.Value.ToString().Split("_");
// Avoid duplicate locations from being added to the location list
if (locations.Contains(choppedValues.GetValue(2)))
{
continue;
}
locations.Add(choppedValues);
}
}
catch (Exception ex)
{
Log.Debug($"Failed to configure locations for {i.Key}");
Log.Debug(ex.Message);
// Print stacktrace to the debug console if applicable
if (!string.IsNullOrEmpty(ex.StackTrace))
{
Log.Debug(ex.StackTrace);
// Avoid duplicate locations from being added to the location list
if (locations.Contains(choppedValues.GetValue(2)))
{
continue;
}
locations.Add(choppedValues);
}
}
catch (Exception ex)
{
Log.Debug($"Failed to configure locations for {i.Key}");
Log.Debug(ex.Message);
// Print stacktrace to the debug console if applicable
if (!string.IsNullOrEmpty(ex.StackTrace))
{
Log.Debug(ex.StackTrace);
}
}
}
}
}
}
}
@@ -552,30 +564,35 @@ public class Program
if (airport != null)
{
if (airport.ParsedData.location.iataCode != null)
if (airport.ParsedData.location != null)
{
foreach (string? apId in airport.ParsedData.location.iataCode)
if (airport.ParsedData.location.iataCode != null)
{
if (apId != null)
foreach (string? apId in airport.ParsedData.location.iataCode)
{
tempLF.arptId = apId;
break;
if (apId != null)
{
tempLF.arptId = apId;
break;
}
}
}
}
}
if (ski != null)
{
if (ski.ParsedData.location.skiId != null)
if (ski.ParsedData.location != null)
{
foreach (string? skiId in ski.ParsedData.location.skiId)
if (ski.ParsedData.location.skiId != null)
{
if (skiId != null)
foreach (string? skiId in ski.ParsedData.location.skiId)
{
tempLF.skiId = skiId;
break;
if (skiId != null)
{
tempLF.skiId = skiId;
break;
}
}
}
}
@@ -584,32 +601,44 @@ public class Program
if (obs != null)
{
int obsIdx = 0;
foreach (string? obsId in obs.ParsedData.location.stationId)
if (obs.ParsedData.location != null)
{
if (obsId != null)
if (obs.ParsedData.location.stationId != null)
{
if (obsIdx == 0)
foreach (string? obsId in obs.ParsedData.location.stationId)
{
tempLF.obsStn = obsId;
tempLF.idxId = obsId;
} else if (obsIdx == 1)
{
tempLF.secObsStn = obsId;
} else if (obsIdx == 2)
{
tempLF.tertObsStn = obsId;
} else
{
break;
if (obs.ParsedData.location != null)
{
if (obsId != null)
{
if (obsIdx == 0)
{
tempLF.obsStn = obsId;
tempLF.idxId = obsId;
} else if (obsIdx == 1)
{
tempLF.secObsStn = obsId;
} else if (obsIdx == 2)
{
tempLF.tertObsStn = obsId;
} else
{
break;
}
obsIdx += 1;
}
}
}
obsIdx += 1;
}
}
}
if (al != null)
{
tempLF.cliStn = al.ParsedData.stationId.First();
if (al.ParsedData.stationId != null)
{
tempLF.cliStn = al.ParsedData.stationId.First();
}
}
if (cc != null)
+116 -109
View File
@@ -382,11 +382,12 @@ public class AlertBulletin : I2Record
public async Task<string?> MakeRecord(List<GenericResponse<AlertDetailResponse>> alertDetails)
{
string recordPath = Path.Combine(AppContext.BaseDirectory, "temp", "BERecord.xml");
BERecordRoot root = new BERecordRoot();
List<BERecord> alerts = new List<BERecord>();
root.Type = "BERecord";
root.BERecord = alerts;
List<BERecord> alerts = new();
BERecordRoot root = new()
{
Type = "BERecord",
BERecord = alerts
};
if (alertDetails.Count < 1)
{
@@ -397,115 +398,121 @@ public class AlertBulletin : I2Record
foreach (var details in alertDetails)
{
var detail = details.ParsedData.alertDetail;
var locationInfo = details.Location;
BERecord record = new BERecord();
BEHdr header = new BEHdr();
BEvent bEvent = new BEvent();
BLocations locations = new BLocations();
BStCd stateInfo = new BStCd();
BEData data = new BEData();
BHdln headline = new BHdln();
BNarrTxt narrative = new BNarrTxt();
AlertDetail? detail = details.ParsedData.alertDetail;
LFRecordLocation locationInfo = details.Location;
// Timestamp parsing
var endTime = DateTimeOffset.FromUnixTimeSeconds(detail.endTimeUTC).ToString("yyyy MM dd HH mm")
.Replace(" ", "");
var expireTime = DateTimeOffset.FromUnixTimeSeconds(detail.expireTimeUTC)
.ToString("yyyy MM dd HH mm").Replace(" ", "");
var issueTime = DateTime.Parse(detail.issueTimeLocal).ToString("yyyy MM dd HH mm").Replace(" ", "");
var processTime = DateTimeOffset.FromUnixTimeSeconds(detail.processTimeUTC).ToString("yyyy MM dd HH mm ss")
.Replace(" ", "");
record.Id = "0000000";
record.LocationKey =
$"{detail.areaId}_{detail.phenomena}_{detail.significance}_{detail.eventTrackingNumber}_{detail.officeCode}";
record.Action = "1";
record.ClientKey = record.LocationKey;
record.BEHdr = header;
record.BEData = data;
header.BPIL = detail.productIdentifier;
header.BEvent = bEvent;
header.BSgmntChksum = detail.identifier;
header.ProcTm = processTime;
EActionCd eActionCd = new EActionCd();
eActionCd.EActionPriority = detail.messageTypeCode;
EOfficeId eOfficeId = new EOfficeId();
eOfficeId.EOfficeNm = detail.officeName;
eOfficeId.Text = detail.officeCode;
switch (detail.messageType)
if (detail != null)
{
case "Update":
eActionCd.Text = "CON";
break;
case "New":
eActionCd.Text = "NEW";
break;
}
if (locationInfo.gmtDiff != null)
{
bEvent.EStTmUTC = locationInfo.gmtDiff;
string endTime = DateTimeOffset.FromUnixTimeSeconds(detail.endTimeUTC).ToString("yyyy MM dd HH mm").Replace(" ", "");
string expireTime = DateTimeOffset.FromUnixTimeSeconds(detail.expireTimeUTC).ToString("yyyy MM dd HH mm").Replace(" ", "");
string issueTime = DateTime.Parse(detail.issueTimeLocal ?? "").ToString("yyyy MM dd HH mm").Replace(" ", "");
string processTime = DateTimeOffset.FromUnixTimeSeconds(detail.processTimeUTC).ToString("yyyy MM dd HH mm ss").Replace(" ", "");
EActionCd eActionCd = new() {EActionPriority = detail.messageTypeCode};
switch (detail.messageType)
{
case "Update":
eActionCd.Text = "CON";
break;
case "New":
eActionCd.Text = "NEW";
break;
}
EOfficeId eOfficeId = new() {EOfficeNm = detail.officeName, Text = detail.officeCode};
BEvent bEvent = new()
{
ETWCIId = twcIdIdx.ToString(),
EActionCd = eActionCd,
EOfficeId = eOfficeId,
EPhenom = detail.phenomena,
EETN = detail.eventTrackingNumber,
EDesc = detail.eventDescription,
EEndTmUTC = endTime,
ESvrty = detail.severityCode,
EExpTmUTC = expireTime,
EStTmUTC = locationInfo.gmtDiff ?? ""
};
BStCd stateInfo = new()
{
BSt = _states[locationInfo.stCd],
Text = locationInfo.stCd
};
BLocCd loc = new()
{
BLoc = detail.areaName,
BLocTyp = detail.areaTypeCode,
Text = detail.areaId
};
BLocations locations = new()
{
BStCd = stateInfo,
BLocCd = loc,
BCntryCd = detail.countryCode,
BTzAbbrv = detail.effectiveTimeLocalTimeZone,
BUTCDiff = locationInfo.gmtDiff ?? ""
};
BEHdr header = new()
{
BPIL = detail.productIdentifier,
BEvent = bEvent,
BSgmntChksum = detail.identifier,
ProcTm = processTime,
BLocations = locations
};
BHdln headline = new()
{
BHdlnTxt = detail.headlineText,
BVocHdlnCd = MapVocalCode($"{detail.phenomena}_{detail.significance}")
};
BNarrTxt narrative = new()
{
BNarrTxtLang = "en_US"
};
BEData data = new()
{
BIssueTmUTC = issueTime,
BHdln = headline,
BNarrTxt = narrative
};
BERecord record = new()
{
Id = "0000000",
LocationKey = $"{detail.areaId}_{detail.phenomena}_{detail.significance}_{detail.eventTrackingNumber}_{detail.officeCode}",
Action = "1",
ClientKey = $"{detail.areaId}_{detail.phenomena}_{detail.significance}_{detail.eventTrackingNumber}_{detail.officeCode}",
BEHdr = header,
BEData = data
};
if (detail.texts != null)
{
string narrtxt = detail.texts[0].description ?? "".Replace("\n", "");
if (narrtxt.Count() >= 764)
{
narrtxt = narrtxt.Substring(0, 764);
narrtxt += "...";
}
narrative.BLn = detail.texts[0].description ?? "".Replace("\n", "");
}
twcIdIdx += 1;
alerts.Add(record);
}
bEvent.ETWCIId = twcIdIdx.ToString();
bEvent.EActionCd = eActionCd;
bEvent.EOfficeId = eOfficeId;
bEvent.EPhenom = detail.phenomena;
bEvent.ESgnfcnc = detail.significance;
bEvent.EETN = detail.eventTrackingNumber;
bEvent.EDesc = detail.eventDescription;
bEvent.EEndTmUTC = endTime;
bEvent.ESvrty = detail.severityCode;
bEvent.EExpTmUTC = expireTime;
BLocCd loc = new BLocCd();
loc.BLoc = detail.areaName;
loc.BLocTyp = detail.areaTypeCode;
loc.Text = detail.areaId;
stateInfo.BSt = _states[locationInfo.stCd];
stateInfo.Text = locationInfo.stCd;
if (locationInfo.stCd == null)
{
stateInfo.BSt = "International";
stateInfo.Text = "INTL";
}
if (locationInfo.gmtDiff != null)
{
locations.BUTCDiff = locationInfo.gmtDiff;
}
locations.BStCd = stateInfo;
locations.BLocCd = loc;
locations.BCntryCd = detail.countryCode;
locations.BTzAbbrv = detail.effectiveTimeLocalTimeZone;
header.BLocations = locations;
data.BIssueTmUTC = issueTime;
data.BHdln = headline;
data.BNarrTxt = narrative;
headline.BHdlnTxt = detail.headlineText;
headline.BVocHdlnCd = MapVocalCode($"{detail.phenomena}_{detail.significance}");
narrative.BNarrTxtLang = "en_US";
string narrtxt = detail.texts[0].description.Replace("\n", "");
if (narrtxt.Count() >= 764)
{
narrtxt = narrtxt.Substring(0, 764);
narrtxt += "...";
}
narrative.BLn = detail.texts[0].description.Replace("\n", "");
twcIdIdx += 1;
alerts.Add(record);
}
XmlSerializer serializer = new XmlSerializer(typeof(BERecordRoot));
@@ -17,8 +17,8 @@ public class ClimatologyRecord : I2Record
foreach (var result in results)
{
ClimatologyRecordResponse cliRecRes = new ClimatologyRecordResponse();
List<ClimatologyRec> cliRecList = new List<ClimatologyRec>();
ClimatologyRecordResponse cliRecRes = new();
List<ClimatologyRec> cliRecList = new();
if (result.Location.cliStn != null)
{
cliRecRes.Key = result.Location.cliStn;
@@ -29,98 +29,48 @@ public class ClimatologyRecord : I2Record
}
cliRecRes.ClimoRec = cliRecList;
for (var i = 0; i < result.ParsedData.almanacInterval.Count(); i++)
if (result.ParsedData.almanacInterval != null)
{
ClimatologyRec cliRec = new ClimatologyRec();
if (result.Location.cliStn != null)
for (var i = 0; i < result.ParsedData.almanacInterval.Count; i++)
{
cliRec.Loc = result.Location.cliStn;
} else
{
cliRec.Loc = "0";
}
if (result.ParsedData.temperatureAverageMax != null)
{
if (result.ParsedData.temperatureAverageMax[i] != null)
ClimatologyRec cliRec = new()
{
cliRec.AvgHigh = Convert.ToInt32(result.ParsedData.temperatureAverageMax[i]);
}
Loc = result.Location.cliStn ?? "0",
AvgHigh = (result.ParsedData.temperatureAverageMax ?? Enumerable.Repeat<int?>(null, result.ParsedData.almanacInterval.Count).ToList())[i] ?? 0,
AvgLow = (result.ParsedData.temperatureAverageMin ?? Enumerable.Repeat<int?>(null, result.ParsedData.almanacInterval.Count).ToList())[i] ?? 0,
RecHigh = (result.ParsedData.temperatureRecordMax ?? Enumerable.Repeat<int?>(null, result.ParsedData.almanacInterval.Count).ToList())[i] ?? 0,
RecLow = (result.ParsedData.temperatureRecordMin ?? Enumerable.Repeat<int?>(null, result.ParsedData.almanacInterval.Count).ToList())[i] ?? 0,
RecHighYear = (result.ParsedData.almanacRecordYearMax ?? Enumerable.Repeat<int?>(null, result.ParsedData.almanacInterval.Count).ToList())[i] ?? 2026,
RecLowYear = (result.ParsedData.almanacRecordYearMin ?? Enumerable.Repeat<int?>(null, result.ParsedData.almanacInterval.Count).ToList())[i] ?? 2026,
Year = System.DateTime.Now.Year,
Month = (result.ParsedData.almanacRecordDate ?? Enumerable.Repeat<string>("1220", result.ParsedData.almanacInterval.Count).ToList())[i][..2],
Day = (result.ParsedData.almanacRecordDate ?? Enumerable.Repeat<string>("1220", result.ParsedData.almanacInterval.Count).ToList())[i][3..]
};
}
if (result.ParsedData.temperatureAverageMin != null)
{
if (result.ParsedData.temperatureAverageMin[i] != null)
cliRecList.Add(cliRec);
if (i == result.ParsedData.almanacInterval.Count - 1)
{
cliRec.AvgLow = Convert.ToInt32(result.ParsedData.temperatureAverageMin[i]);
}
}
if (result.ParsedData.temperatureRecordMax != null)
{
if (result.ParsedData.temperatureRecordMax[i] != null)
{
cliRec.RecHigh = Convert.ToInt32(result.ParsedData.temperatureRecordMax[i]);
}
}
if (result.ParsedData.temperatureRecordMin != null)
{
if (result.ParsedData.temperatureRecordMin[i] != null)
{
cliRec.RecLow = Convert.ToInt32(result.ParsedData.temperatureRecordMin[i]);
}
}
if (result.ParsedData.almanacRecordYearMax != null)
{
if (result.ParsedData.almanacRecordYearMax[i] != null)
{
cliRec.RecHighYear = Convert.ToInt32(result.ParsedData.almanacRecordYearMax[i]);
}
}
if (result.ParsedData.almanacRecordYearMin != null)
{
if (result.ParsedData.almanacRecordYearMin[i] != null)
{
cliRec.RecLowYear = Convert.ToInt32(result.ParsedData.almanacRecordYearMin[i]);
}
}
ClimatologyRec todayCliRec = new()
{
Loc = result.Location.cliStn ?? "0",
AvgHigh = cliRec.AvgHigh,
AvgLow = cliRec.AvgLow,
RecHigh = cliRec.RecHigh,
RecHighYear = cliRec.RecHighYear,
RecLow = cliRec.RecLow,
RecLowYear = cliRec.RecLowYear,
Year = System.DateTime.Now.Year,
Month = System.DateTime.Now.ToString("MM"),
Day = System.DateTime.Now.ToString("dd")
};
cliRec.Year = System.DateTime.Now.Year;
cliRec.Month = result.ParsedData.almanacRecordDate[i].Substring(0,2);
cliRec.Day = result.ParsedData.almanacRecordDate[i].Substring(2,2);
cliRecList.Add(cliRec);
if (i == result.ParsedData.almanacInterval.Count() - 1)
{
ClimatologyRec todayCliRec = new ClimatologyRec();
if (result.Location.cliStn != null)
{
todayCliRec.Loc = result.Location.cliStn;
} else
{
todayCliRec.Loc = "0";
cliRecList.Add(todayCliRec);
}
todayCliRec.AvgHigh = cliRec.AvgHigh;
todayCliRec.AvgLow = cliRec.AvgLow;
todayCliRec.RecHigh = cliRec.RecHigh;
todayCliRec.RecHighYear = cliRec.RecHighYear;
todayCliRec.RecLow = cliRec.RecLow;
todayCliRec.RecLowYear = cliRec.RecLowYear;
todayCliRec.Year = System.DateTime.Now.Year;
todayCliRec.Month = System.DateTime.Now.ToString("MM");
todayCliRec.Day = System.DateTime.Now.ToString("dd");
cliRecList.Add(todayCliRec);
}
}
XmlSerializer serializer = new XmlSerializer(typeof(ClimatologyRecordResponse));
StringWriter sw = new StringWriter();
XmlSerializer serializer = new(typeof(ClimatologyRecordResponse));
StringWriter sw = new();
XmlWriter xw = XmlWriter.Create(sw, new XmlWriterSettings
{
OmitXmlDeclaration = true,
+64 -87
View File
@@ -16,103 +16,80 @@ public class DHRecord : I2Record
foreach (var result in results)
{
DHRecordResponse dHRecRes = new DHRecordResponse();
List<DHRecordData> dhRecordDataList = new List<DHRecordData>();
DHRecordResponse dHRecRes = new();
List<DHRecordData> dhRecordDataList = new();
dHRecRes.DHRecordData = dhRecordDataList;
DHRecordHeader dHRecHdr = new DHRecordHeader();
if (result.Location.coopId != null)
DHRecordHeader dHRecHdr = new()
{
dHRecHdr.CoopId = result.Location.coopId;
} else
{
dHRecHdr.CoopId = "0";
Log.Warning($"Location {result.Location.locId} has no coopId!");
}
dHRecHdr.ILevel = 2;
if (result.Location.prsntNm != null)
{
dHRecHdr.StnNm = result.Location.prsntNm;
}
dHRecHdr.ProcTm = System.DateTime.Now.ToString("yyyyMMddHHmmss");
CoopId = result.Location.coopId ?? "0",
StnNm = result.Location.prsntNm ?? "",
ProcTm = System.DateTime.Now.ToString("yyyyMMddHHmmss"),
ILevel = 2
};
foreach (var fcst in result.ParsedData.Forecasts.Forecast)
{
DHRecordData dHRecData = new DHRecordData();
dHRecData.hourNum = fcst.Num - 1;
dHRecData.dayOfWeek = fcst.Dow;
DateTimeOffset fcstValid = DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64(fcst.FcstValid));
dHRecData.FcstValidGMT = fcst.FcstValid;
dHRecData.FcstValidDay = fcstValid.ToString("yyyyddMM");
dHRecData.FcstValidTime = fcstValid.ToString("HHmmss");
dHRecData.LocValidDay = fcstValid.ToString("yyyyddMM");
dHRecData.LocValidTime = fcstValid.ToString("HHmmss");
dHRecData.LocalValidTime = $"{fcstValid.ToString("ddd dd MMM yyyy hh:mm:ss tt ")}GMT";
dHRecData.TempF = fcst.Temp;
dHRecData.TempC = Convert.ToInt32((fcst.Temp - 32) / 1.8);
// No data for sky ceiling I assume?
dHRecData.Sky = 27;
dHRecData.SkyX = 2700;
dHRecData.SensibleWx = fcst.Phrase32char;
dHRecData.TSensibleWx = fcst.Phrase22char;
dHRecData.ProbsOfPrecip = fcst.Pop;
// No cPOS data
dHRecData.chanceProbsOfSnow = 0;
dHRecData.RelativeHumidity = fcst.Rh;
dHRecData.WindSpeedMiles = fcst.Wspd;
dHRecData.WindSpeedKm = Convert.ToInt32(fcst.Wspd * 1.60934);
dHRecData.WindSpeedKnots = Convert.ToInt32(fcst.Wspd * 0.868976);
dHRecData.windDir = fcst.Wdir;
dHRecData.windDirCardinal = fcst.WdirCardinal;
if (fcst.Hi != null)
if (result.ParsedData.Forecasts != null) {
if (result.ParsedData.Forecasts.Forecast != null)
{
dHRecData.heatIndexF = fcst.Hi.Value;
}
dHRecData.heatIndexC = Convert.ToInt32((fcst.Hi - 32) / 1.8);
dHRecData.windChillF = fcst.Wc;
dHRecData.windChillC = Convert.ToInt32((fcst.Wc - 32) / 1.8);
dHRecData.visiblityMiles = Convert.ToInt32(fcst.Vis);
dHRecData.visiblityKm = Convert.ToInt32(fcst.Vis * 1.60934);
dHRecData.cloudCover = fcst.Clds;
dHRecData.dewPointF = fcst.Dewpt;
dHRecData.dewPointC = Convert.ToInt32((fcst.Dewpt - 32) / 1.8);
dHRecData.uvIndex = fcst.UvIndex;
dHRecData.uvIndexRaw = fcst.UvIndexRaw;
if (fcst.GolfIndex != null)
{
dHRecData.GolfIndex = fcst.GolfIndex;
}
if (fcst.GolfCategory != null)
{
dHRecData.GolfCategory = fcst.GolfCategory;
}
dHRecData.PrecipType = fcst.PrecipType;
// Day/Night not provided
if (DateTime.Now.Hour >= 18)
{
if (DateTime.Now.Hour < 6)
foreach (var fcst in result.ParsedData.Forecasts.Forecast)
{
dHRecData.dayNightIdx = "N";
}
} else
{
dHRecData.dayNightIdx = "D";
DateTimeOffset fcstValid = DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64(fcst.FcstValid));
string UnitConfig = Config.config.LocalStarConfig.Unit;
DHRecordData dHRecData = new()
{
hourNum = fcst.Num - 1,
dayOfWeek = fcst.Dow ?? "",
FcstValidGMT = fcst.FcstValid ?? "",
FcstValidDay = fcstValid.ToString("yyyyddMM"),
FcstValidTime = fcstValid.ToString("yyyyddMM"),
LocValidDay = fcstValid.ToString("yyyyddMM"),
LocValidTime = fcstValid.ToString("HHmmss"),
LocalValidTime = $"{fcstValid.ToString("ddd dd MMM yyyy hh:mm:ss tt ")}GMT",
TempF = fcst.Temp,
TempC = Convert.ToInt32((fcst.Temp - 32) / 1.8),
// No data for sky ceiling I assume?
Sky = 27,
SkyX = 2700,
SensibleWx = fcst.Phrase32char ?? "",
TSensibleWx = fcst.Phrase22char ?? "",
ProbsOfPrecip = fcst.Pop,
// No cPOS data
chanceProbsOfSnow = 0,
RelativeHumidity = fcst.Rh,
WindSpeedMiles = fcst.Wspd,
WindSpeedKm = Convert.ToInt32(fcst.Wspd * 1.60934),
WindSpeedKnots = Convert.ToInt32(fcst.Wspd * 0.868976),
windDir = fcst.Wdir,
windDirCardinal = fcst.WdirCardinal ?? "",
heatIndexF = Convert.ToInt32(fcst.Hi),
windChillF = fcst.Wc,
windChillC = Convert.ToInt32((fcst.Wc - 32) / 1.8),
visiblityMiles = Convert.ToInt32(fcst.Vis),
visiblityKm = Convert.ToInt32(fcst.Vis * 1.60934),
cloudCover = fcst.Clds,
dewPointF = fcst.Dewpt,
dewPointC = Convert.ToInt32((fcst.Dewpt - 32) / 1.8),
uvIndex = fcst.UvIndex,
uvIndexRaw = fcst.UvIndexRaw,
GolfIndex = fcst.GolfIndex ?? "",
GolfCategory = fcst.GolfCategory ?? "",
PrecipType = fcst.PrecipType ?? "",
dayNightIdx = fcst.DayInd ?? "",
wxman = fcst.Wxman ?? "",
SubphrasePt1 = fcst.SubphrasePt1 ?? "",
SubphrasePt2 = fcst.SubphrasePt2 ?? "",
SubphrasePt3 = fcst.SubphrasePt3 ?? ""
};
// wtf is with HourlyForecast schema
dhRecordDataList.Add(dHRecData);
}
}
dHRecData.wxman = fcst.Wxman;
dHRecData.SubphrasePt1 = fcst.SubphrasePt1;
dHRecData.SubphrasePt2 = fcst.SubphrasePt2;
dHRecData.SubphrasePt3 = fcst.SubphrasePt3;
// wtf is with HourlyForecast schema
dhRecordDataList.Add(dHRecData);
}
XmlSerializer serializer = new XmlSerializer(typeof(DHRecordResponse));
StringWriter sw = new StringWriter();
XmlSerializer serializer = new(typeof(DHRecordResponse));
StringWriter sw = new();
XmlWriter xw = XmlWriter.Create(sw, new XmlWriterSettings
{
OmitXmlDeclaration = true,
@@ -91,18 +91,25 @@ public class DailyForecastRecord : I2Record
});
// check for potential severe weather qualifiers
foreach (Forecast fcst in result.ParsedData.Forecasts.Forecast)
{
fcst.QualifierCode = QualifierCheck(fcst.SnowQpf,0, fcst.MinTemp, fcst.Qpf);
if (fcst.Day != null)
if (result.ParsedData.Forecasts != null)
{
if (result.ParsedData.Forecasts.Forecast != null)
{
fcst.Day.QualifierCode = QualifierCheck(fcst.Day.SnowQpf, fcst.Day.IconCode, fcst.Day.Temp, fcst.Day.Qpf);
}
if (fcst.Night != null)
{
fcst.Night.QualifierCode = QualifierCheck(fcst.Night.SnowQpf, fcst.Night.IconCode, fcst.Night.Temp, fcst.Night.Qpf);
}
foreach (Forecast fcst in result.ParsedData.Forecasts.Forecast)
{
fcst.QualifierCode = QualifierCheck(fcst.SnowQpf,0, fcst.MinTemp, fcst.Qpf);
if (fcst.Day != null)
{
fcst.Day.QualifierCode = QualifierCheck(fcst.Day.SnowQpf, fcst.Day.IconCode, fcst.Day.Temp, fcst.Day.Qpf);
}
if (fcst.Night != null)
{
fcst.Night.QualifierCode = QualifierCheck(fcst.Night.SnowQpf, fcst.Night.IconCode, fcst.Night.Temp, fcst.Night.Qpf);
}
}
}
}
xw.WriteWhitespace("");
serializer.Serialize(xw, result.ParsedData);
+21 -17
View File
@@ -17,27 +17,31 @@ public class HolidayMapping : I2Record
CultureInfo provider = CultureInfo.InvariantCulture;
foreach (var holiday in result.Holidays)
if (result.Holidays != null)
{
DateTime date = DateTime.ParseExact(holiday.Date, "yyyyMMdd", provider);
DateTime dateNew = new DateTime(DateTime.Now.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second);
DateTime now = DateTime.Now;
Log.Debug($"It is currently {now.ToString()}");
if (now > dateNew)
foreach (var holiday in result.Holidays)
{
Log.Debug($"Holiday {holiday.Name} has already past,");
DateTime newDate = new DateTime(dateNew.Year + 1, date.Month, date.Day, date.Hour, date.Minute, date.Second);
Log.Debug($"new date is {newDate.ToString()}");
holiday.Date = newDate.ToString("yyyyMMdd");
holiday.DateFormatted = newDate.ToString("MM/dd/yyyy");
continue;
}
DateTime date = DateTime.ParseExact(holiday.Date ?? "20260119", "yyyyMMdd", provider);
DateTime dateNew = new(DateTime.Now.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second);
DateTime now = DateTime.Now;
holiday.Date = dateNew.ToString("yyyyMMdd");
holiday.DateFormatted = dateNew.ToString("MM/dd/yyyy");
Log.Debug($"It is currently {now.ToString()}");
if (now > dateNew)
{
Log.Debug($"Holiday {holiday.Name} has already past,");
DateTime newDate = new(dateNew.Year + 1, date.Month, date.Day, date.Hour, date.Minute, date.Second);
Log.Debug($"new date is {newDate.ToString()}");
holiday.Date = newDate.ToString("yyyyMMdd");
holiday.DateFormatted = newDate.ToString("MM/dd/yyyy");
continue;
}
holiday.Date = dateNew.ToString("yyyyMMdd");
holiday.DateFormatted = dateNew.ToString("MM/dd/yyyy");
}
}
XmlSerializer serializer = new XmlSerializer(typeof(HolidayMappingResponse));
StringWriter sw = new StringWriter();
+54 -55
View File
@@ -19,61 +19,60 @@ public class LFRecord : I2Record
string recordPath = Path.Combine(AppContext.BaseDirectory, "temp", "LFRecords", $"LFRecord-{result.cntryCd}-{result.locType}-{result.locId}-{result.cityNm}.xml");
string recordScript = "<Data type=\"LFRecord\">";
LFRecordResponse LFRecRes = new LFRecordResponse();
LFRecordHeader LFRecHdr = new LFRecordHeader();
LFRecHdr.LocId = result.locId;
LFRecHdr.LocType = result.locType;
LFRecHdr.ProcTm = System.DateTime.Now.ToString("yyyyMMddHHmmss");
LFRecRes.LFRecordHeader = LFRecHdr;
// Set the LFRecord values
LFRecordData LFRecData = new LFRecordData();
LFRecData.active = result.active;
LFRecData.arptId = result.arptId;
LFRecData.cityNm = result.cityNm;
LFRecData.cliStn = result.cliStn;
LFRecData.clsRad = result.clsRad;
LFRecData.cntryCd = result.cntryCd;
LFRecData.cntyFips = result.cntyFips;
LFRecData.cntyId = result.cntyId;
LFRecData.cntyNm = result.cntyNm;
LFRecData.coopId = result.coopId;
LFRecData.dmaCd = result.dmaCd;
LFRecData.dySTAct = result.dySTAct;
LFRecData.dySTInd = result.dySTInd;
LFRecData.elev = result.elev;
LFRecData.epaId = result.epaId;
LFRecData.gmtDiff = result.gmtDiff;
LFRecData.lat = result.lat;
LFRecData.lon = result.@long;
LFRecData.lsRad = result.lsRad;
LFRecData.mrnZoneId = result.mrnZoneId;
LFRecData.obsStn = result.obsStn;
LFRecData.pllnId = result.pllnId;
LFRecData.primTecci = result.primTecci;
LFRecData.prsntNm = result.prsntNm;
LFRecData.regSat = result.regSat;
LFRecData.secObsStn = result.secObsStn;
LFRecData.secTecci = result.secTecci;
LFRecData.siteId = result.siteId;
LFRecData.skiId = result.skiId;
LFRecData.ssRad = result.ssRad;
LFRecData.stCd = result.stCd;
LFRecData.tertObsStn = result.tertObsStn;
LFRecData.tertTecci = result.tertTecci;
LFRecData.tideId = result.tideId;
LFRecData.tmZnNm = result.tmZnNm;
LFRecData.tmZnAbbr = result.tmZnAbbr;
LFRecData.tPrsntNm = result.tPrsntNm;
LFRecData.wmoId = result.wmoId;
LFRecData.wrlsPrsntNm = result.wrlsPrsntNm;
LFRecData.zip2locId = result.zip2locId;
LFRecData.zoneId = result.zoneId;
LFRecData.zoneNm = result.cntyNm;
LFRecRes.LFRecordData = LFRecData;
LFRecordResponse LFRecRes = new()
{
LFRecordHeader = new LFRecordHeader()
{
LocId = result.locId,
LocType = result.locType,
ProcTm = System.DateTime.Now.ToString("yyyyMMddHHmmss")
},
LFRecordData = new LFRecordData()
{
active = result.active,
arptId = result.arptId,
cityNm = result.cityNm,
cliStn = result.cliStn,
clsRad = result.clsRad,
cntryCd = result.cntryCd,
cntyFips = result.cntyFips,
cntyId = result.cntyId,
cntyNm = result.cntyNm,
coopId = result.coopId,
dmaCd = result.dmaCd,
dySTAct = result.dySTAct,
dySTInd = result.dySTInd,
elev = result.elev,
epaId = result.epaId,
gmtDiff = result.gmtDiff,
lat = result.lat,
lon = result.@long,
lsRad = result.lsRad,
mrnZoneId = result.mrnZoneId,
obsStn = result.obsStn,
pllnId = result.pllnId,
primTecci = result.primTecci,
prsntNm = result.prsntNm,
regSat = result.regSat,
secObsStn = result.secObsStn,
secTecci = result.secTecci,
siteId = result.siteId,
skiId = result.skiId,
ssRad = result.ssRad,
stCd = result.stCd,
tertObsStn = result.tertObsStn,
tertTecci = result.tertTecci,
tideId = result.tideId,
tmZnNm = result.tmZnNm,
tmZnAbbr = result.tmZnAbbr,
tPrsntNm = result.tPrsntNm,
wmoId = result.wmoId,
wrlsPrsntNm = result.wrlsPrsntNm,
zip2locId = result.zip2locId,
zoneId = result.zoneId,
zoneNm = result.cntyNm,
}
};
XmlSerializer serializer = new XmlSerializer(typeof(LFRecordResponse));
StringWriter sw = new StringWriter();
+39 -29
View File
@@ -135,40 +135,50 @@ public class RadarProcess
if (mpc != null)
{
foreach (ConfigItem cfgItm in mpc.ConfigDef.ConfigItems.ConfigItem)
if (mpc.ConfigDef != null)
{
if (cfgItm.Key == "PrimaryLatitudeLongitude")
if (mpc.ConfigDef.ConfigItems != null)
{
Point<double> latlong = new((double)0.0, (double)0.0);
string[] split = cfgItm.Value.Split("-");
string split0Dir = split[0].Substring(0, 1);
string split1Dir = split[1].Substring(0, 1);
if (mpc.ConfigDef.ConfigItems.ConfigItem != null)
{
foreach (ConfigItem cfgItm in mpc.ConfigDef.ConfigItems.ConfigItem)
{
if (cfgItm.Key == "PrimaryLatitudeLongitude")
{
Point<double> latlong = new((double)0.0, (double)0.0);
string[] split = (cfgItm.Value ?? "-").Split("-");
string split0Dir = split[0].Substring(0, 1);
string split1Dir = split[1].Substring(0, 1);
if (split0Dir == "W")
{
latlong.Y = Convert.ToDouble($"-{split[0].Substring(1)}");
} else
{
latlong.Y = Convert.ToDouble(split[0].Substring(1));
if (split0Dir == "W")
{
latlong.Y = Convert.ToDouble($"-{split[0].Substring(1)}");
} else
{
latlong.Y = Convert.ToDouble(split[0].Substring(1));
}
if (split1Dir == "N")
{
latlong.X = Convert.ToDouble(split[1].Substring(1));
} else
{
latlong.X = Convert.ToDouble($"-{split[1].Substring(1)}");
}
Point<int> tile = LongLatToTile(latlong);
GrabXStart = tile.X - Config.config.RadarConfiguration.LocalRadarRadius;
GrabXEnd = tile.X + Config.config.RadarConfiguration.LocalRadarRadius;
GrabYStart = tile.Y - Config.config.RadarConfiguration.LocalRadarRadius;
GrabYEnd = tile.Y + Config.config.RadarConfiguration.LocalRadarRadius;
//throw new Exception($"{GrabXStart} \n {GrabXEnd} \n {GrabYStart} \n {GrabYEnd}");
break;
}
}
}
if (split1Dir == "N")
{
latlong.X = Convert.ToDouble(split[1].Substring(1));
} else
{
latlong.X = Convert.ToDouble($"-{split[1].Substring(1)}");
}
Point<int> tile = LongLatToTile(latlong);
GrabXStart = tile.X - Config.config.RadarConfiguration.LocalRadarRadius;
GrabXEnd = tile.X + Config.config.RadarConfiguration.LocalRadarRadius;
GrabYStart = tile.Y - Config.config.RadarConfiguration.LocalRadarRadius;
GrabYEnd = tile.Y + Config.config.RadarConfiguration.LocalRadarRadius;
//throw new Exception($"{GrabXStart} \n {GrabXEnd} \n {GrabYStart} \n {GrabYEnd}");
break;
}
}
}
} else
{
Log.Warning("Could not read MachineProductCfg!");
+27 -19
View File
@@ -16,31 +16,39 @@ public class TIRecord : I2Record
foreach (var result in results)
{
TIRecordResponse dHRecRes = new TIRecordResponse();
List<TIRecordData> dhRecordDataList = new List<TIRecordData>();
TIRecordResponse dHRecRes = new()
{
TIRecordHeader = new TIRecordHeader()
{
TIstnId = result.Location.tideId,
ILevel = 2,
ProcTm = System.DateTime.Now.ToString("yyyyMMddHHmmss")
}
};
List<TIRecordData> dhRecordDataList = new();
dHRecRes.TIRecordData = dhRecordDataList;
TIRecordHeader dHRecHdr = new TIRecordHeader();
dHRecHdr.TIstnId = result.Location.tideId;
dHRecHdr.ILevel = 2;
dHRecHdr.ProcTm = System.DateTime.Now.ToString("yyyyMMddHHmmss");
dHRecRes.TIRecordHeader = dHRecHdr;
foreach (var fcst in result.ParsedData.Tides.Tide)
if (result.ParsedData.Tides != null)
{
TIRecordData dHRecData = new TIRecordData();
DateTime time = DateTime.Parse(fcst.TideTM, null, System.Globalization.DateTimeStyles.RoundtripKind);
dHRecData.TItdTm = time.ToString("MM/dd/yyyy HH:mm:ss");
dHRecData.TItdHght = fcst.TideHt;
dHRecData.TItdTyp = fcst.TideType;
// wtf is with HourlyForecast schema
dhRecordDataList.Add(dHRecData);
if (result.ParsedData.Tides.Tide != null)
{
foreach (var fcst in result.ParsedData.Tides.Tide)
{
TIRecordData dHRecData = new TIRecordData();
DateTime time = DateTime.Parse(fcst.TideTM ?? "", null, System.Globalization.DateTimeStyles.RoundtripKind);
dHRecData.TItdTm = time.ToString("MM/dd/yyyy HH:mm:ss");
dHRecData.TItdHght = fcst.TideHt;
dHRecData.TItdTyp = fcst.TideType;
// wtf is with HourlyForecast schema
dhRecordDataList.Add(dHRecData);
}
}
}
XmlSerializer serializer = new XmlSerializer(typeof(TIRecordResponse));
StringWriter sw = new StringWriter();
XmlSerializer serializer = new(typeof(TIRecordResponse));
StringWriter sw = new();
XmlWriter xw = XmlWriter.Create(sw, new XmlWriterSettings
{
OmitXmlDeclaration = true,