@atmosx/event-product-parser 3.0.621 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/CHANGELOGS.md +52 -0
- package/.github/CODE_OF_CONDUCT.md +24 -1
- package/.github/CONTRIBUTING.md +22 -3
- package/.github/FUNDING.yaml +3 -0
- package/.github/LICENSE +24 -1
- package/.github/SECURITY.md +25 -6
- package/.github/docs/chapters/general-configurations.md +109 -0
- package/.github/docs/chapters/sources-and-attributes.md +219 -0
- package/README.md +56 -146
- package/dist/index.cjs +25333 -0
- package/package.json +17 -11
- package/pnpm-workspace.yaml +4 -0
- package/src/bootstrap.ts +67 -52
- package/src/components/audio/GenerateAudioMessage.ts +149 -0
- package/src/{@modules/@eas → components/audio/components}/GetCleanDescription.ts +2 -2
- package/src/{@modules/@eas → components/audio/components}/GetFloatPCM16.ts +2 -2
- package/src/{@modules/@eas → components/audio/components}/GetMergedPCM16.ts +2 -2
- package/src/{@modules/@eas → components/audio/components}/GetPCM16.ts +13 -8
- package/src/{@modules/@eas → components/audio/components}/GetPCMToFloat.ts +2 -2
- package/src/{@modules/@eas → components/audio/components}/GetSampledPCM16.ts +14 -8
- package/src/{@modules/@eas → components/audio/components}/GetTTS.ts +17 -10
- package/src/{@modules/@eas → components/audio/components}/GetWavPCM16.ts +7 -7
- package/src/{@modules/@eas → components/audio/components}/SetAFSK.ts +13 -8
- package/src/{@modules/@eas → components/audio/components}/SetAsciiToBits.ts +2 -2
- package/src/{@modules/@eas → components/audio/components}/SetAttentionTone.ts +11 -6
- package/src/{@modules/@eas → components/audio/components}/SetNoise.ts +12 -7
- package/src/{@modules/@eas → components/audio/components}/SetRadioEffect.ts +12 -7
- package/src/{@modules/@eas → components/audio/components}/SetSameHeader.ts +22 -14
- package/src/components/database/CreateQuery.ts +39 -0
- package/src/components/database/InitializeDatabase.ts +71 -0
- package/src/components/database/imports/Boundaires.ts +168 -0
- package/src/{@modules/@database/ImportBroadcastify.ts → components/database/imports/Broadcastify.ts} +15 -25
- package/src/components/database/imports/Census.ts +87 -0
- package/src/{@modules/@database/ImportShapefiles.ts → components/database/imports/Shapefiles.ts} +24 -27
- package/src/{@modules/@database/ImportStanza.ts → components/database/imports/Stanza.ts} +15 -19
- package/src/components/events/CreateEvents.ts +88 -0
- package/src/components/events/FilterEvents.ts +149 -0
- package/src/{@building/CreateEvent.ts → components/events/ProcessStanza.ts} +22 -24
- package/src/components/events/RemoveEvents.ts +74 -0
- package/src/{@building → components/events/components}/GetCleanedEvent.ts +2 -2
- package/src/{@building → components/events/components}/GetEventAttachments.ts +14 -12
- package/src/components/events/components/GetEventDirection.ts +28 -0
- package/src/{@building → components/events/components}/GetEventEnhancedName.ts +5 -8
- package/src/{@building → components/events/components}/GetEventGeometry.ts +19 -13
- package/src/{@building → components/events/components}/GetEventHeader.ts +13 -13
- package/src/components/events/components/GetEventMerged.ts +51 -0
- package/src/{@building → components/events/components}/GetEventNodes.ts +22 -20
- package/src/{@building → components/events/components}/GetEventOffice.ts +13 -13
- package/src/components/events/components/GetEventPopulation.ts +58 -0
- package/src/components/events/components/GetEventProperties.ts +106 -0
- package/src/{@building → components/events/components}/GetEventSignature.ts +9 -9
- package/src/{@building → components/events/components}/GetEventTags.ts +3 -3
- package/src/components/events/components/GetEventTheme.ts +26 -0
- package/src/components/events/components/GetEventTracking.ts +64 -0
- package/src/{@modules/@database → components/events/utilities}/GetCachedEvents.ts +18 -15
- package/src/{@manager → components/events/utilities}/SetHash.ts +18 -13
- package/src/{@manager → components/events/utilities}/UpdateEvents.ts +12 -12
- package/src/{@manager → components/events/utilities}/UpdateNode.ts +14 -14
- package/src/{@parsers/@text → components/formatting}/GetEmbededText.ts +14 -8
- package/src/{@parsers/@text → components/formatting}/GetStringText.ts +15 -11
- package/src/{@modules/@utilities → components/geometry}/GetShapeNearestPoint.ts +24 -19
- package/src/components/geometry/GetUnionPolygon.ts +36 -0
- package/src/components/images/GenerateGraphic.ts +242 -0
- package/src/components/images/components/CreateRectangle.ts +22 -0
- package/src/components/images/components/CreateText.ts +22 -0
- package/src/components/images/modules/CreateSVG.ts +37 -0
- package/src/components/images/modules/GetGeographicalBoundaries.ts +72 -0
- package/src/components/images/modules/GetGeographicalCities.ts +58 -0
- package/src/components/images/modules/GetGeographicalEvents.ts +48 -0
- package/src/components/images/modules/GetGeometryBounds.ts +82 -0
- package/src/components/images/modules/GetParsedBoundary.ts +58 -0
- package/src/components/images/modules/GetSVGPath.ts +53 -0
- package/src/components/images/modules/NormalizePolygon.ts +57 -0
- package/src/{@modules/@stanza → components/stanza}/GetAwipsType.ts +16 -17
- package/src/{@modules/@stanza → components/stanza}/ValidateStanza.ts +27 -15
- package/src/{@modules/@utilities → components/utilities}/CreateHttp.ts +26 -26
- package/src/components/utilities/EmitThread.ts +97 -0
- package/src/{@modules/@utilities → components/utilities}/GetLatestIssuance.ts +2 -2
- package/src/{@modules/@utilities → components/utilities}/GetMatched.ts +10 -5
- package/src/components/utilities/QueueManager.ts +70 -0
- package/src/{@modules/@utilities → components/utilities}/SetDebug.ts +13 -13
- package/src/components/utilities/SetEventEmit.ts +42 -0
- package/src/{@modules/@utilities → components/utilities}/SetSettings.ts +7 -7
- package/src/{@modules/@utilities → components/utilities}/SetSleep.ts +5 -5
- package/src/components/utilities/SetTimeoutAction.ts +64 -0
- package/src/components/utilities/SetWarning.ts +47 -0
- package/src/{@modules/@xmpp → components/xmpp}/DeployXMPP.ts +20 -20
- package/src/{@core/CreateListener.ts → components/xmpp/ErrorXMPP.ts} +8 -5
- package/src/{@modules/@xmpp → components/xmpp}/OfflineXMPP.ts +13 -13
- package/src/{@modules/@xmpp → components/xmpp}/OnlineXMPP.ts +18 -18
- package/src/components/xmpp/ReconnectXMPP.ts +64 -0
- package/src/{@modules/@xmpp → components/xmpp}/StanzaXMPP.ts +26 -26
- package/src/{@enums → enums}/AWIPS.ts +2 -2
- package/src/{@enums → enums}/Actions.ts +2 -2
- package/src/{@enums → enums}/Cancellation.ts +2 -2
- package/src/{@enums → enums}/Causes.ts +2 -2
- package/src/{@enums → enums}/Correlations.ts +2 -2
- package/src/{@enums → enums}/Enhanced.ts +4 -3
- package/src/{@enums → enums}/Events.ts +2 -2
- package/src/{@enums → enums}/Expressions.ts +3 -3
- package/src/{@enums → enums}/GlobalFilter.ts +2 -2
- package/src/{@enums → enums}/Hail.ts +2 -2
- package/src/{@enums → enums}/ICAO.ts +2 -2
- package/src/{@enums → enums}/Matches.ts +8 -3
- package/src/{@enums → enums}/Products.ts +2 -2
- package/src/{@enums → enums}/Records.ts +2 -2
- package/src/{@enums → enums}/Severity.ts +2 -2
- package/src/{@enums → enums}/Shapefiles.ts +2 -2
- package/src/{@enums → enums}/States.ts +68 -4
- package/src/{@enums → enums}/Status.ts +2 -2
- package/src/{@enums → enums}/Strings.ts +2 -2
- package/src/{@enums → enums}/Tags.ts +9 -4
- package/src/{@enums → enums}/Testing.ts +2 -2
- package/src/enums/Themes.ts +70 -0
- package/src/events/ParseAPI.ts +133 -0
- package/src/{@events → events}/ParseText.ts +24 -22
- package/src/{@events → events}/ParseUGC.ts +27 -26
- package/src/{@events → events}/ParseVTEC.ts +37 -36
- package/src/{@core → exports}/ClearEvents.ts +9 -9
- package/src/{@core → exports}/GetEvents.ts +4 -4
- package/src/exports/GetNearestCity.ts +45 -0
- package/src/{@core → exports}/GetNodes.ts +4 -4
- package/src/{@core → exports}/GetRandomEvent.ts +4 -4
- package/src/{@core → exports}/GetVersion.ts +4 -4
- package/src/exports/ManualEvent.ts +55 -0
- package/src/{@core → exports}/QueryStanza.ts +12 -11
- package/src/exports/SetNode.ts +100 -0
- package/src/{@core → exports}/StartService.ts +23 -22
- package/src/{@core → exports}/StopService.ts +10 -10
- package/src/index.ts +57 -37
- package/src/{@parsers/@hvtec → parsers/hvtec}/HVExtract.ts +7 -7
- package/src/{@parsers/@text → parsers/text}/GetDescriptionFromProduct.ts +20 -21
- package/src/parsers/text/GetPolygonFromProduct.ts +71 -0
- package/src/{@parsers/@text → parsers/text}/GetTextFromProduct.ts +12 -12
- package/src/parsers/ugc/GetCache.ts +24 -0
- package/src/{@parsers/@ugc → parsers/ugc}/GetExpiry.ts +2 -2
- package/src/{@parsers/@ugc/GetUGCHeader.ts → parsers/ugc/GetHeader.ts} +4 -4
- package/src/{@parsers/@ugc → parsers/ugc}/GetLocations.ts +10 -10
- package/src/parsers/ugc/GetZonePolygon.ts +73 -0
- package/src/{@parsers/@ugc → parsers/ugc}/GetZones.ts +3 -3
- package/src/{@parsers/@ugc → parsers/ugc}/SetCache.ts +13 -8
- package/src/{@parsers/@ugc → parsers/ugc}/UGCExtract.ts +14 -14
- package/src/{@parsers/@pvtec → parsers/vtec}/GetExpiry.ts +2 -2
- package/src/{@parsers/@pvtec → parsers/vtec}/VTECExtract.ts +17 -17
- package/src/tasks/CreateTasks.ts +116 -0
- package/src/tasks/TaskGenerateJSON.ts +34 -0
- package/src/tasks/TaskGenerateText.ts +34 -0
- package/src/tasks/TaskSendNTFY.ts +96 -0
- package/src/tasks/TaskSendWebhook.ts +107 -0
- package/src/{@types → types/event}/Attributes.ts +2 -3
- package/src/{@types → types/event}/Event.ts +8 -7
- package/src/{@types → types/event}/HVTEC.ts +2 -2
- package/src/{@types → types/event}/Properties.ts +17 -3
- package/src/{@types → types/event}/Stanza.ts +2 -2
- package/src/{@types → types/event}/VTEC.ts +8 -8
- package/src/{@types → types/standard}/Actions.ts +3 -3
- package/src/{@types → types/standard}/Hash.ts +5 -5
- package/src/{@modules/@utilities/GetSettings.ts → types/standard/Nodes.ts} +15 -7
- package/src/{@types → types/standard}/Settings.ts +19 -12
- package/src/{@types → types/standard}/StanzaCompiled.ts +15 -15
- package/src/{@types → types/standard}/UGC.ts +5 -5
- package/tools/build.js +32 -0
- package/tsconfig.json +32 -1
- package/.github/SUPPORTED_EVENTS.md +0 -370
- package/.github/docs/docs-functions.md +0 -30
- package/.github/docs/docs-general-configurations.md +0 -209
- package/.github/docs/docs-integrations.md +0 -37
- package/.github/docs/docs-listeners.md +0 -28
- package/.github/docs/docs-source-configuration.md +0 -218
- package/.github/docs/docs-technical.md +0 -50
- package/.github/logo.png +0 -0
- package/.github/samples/SAMPLE_EAS_GENERATION.wav +0 -0
- package/.github/samples/SAMPLE_GEOJSON.json +0 -204
- package/.github/samples/SAMPLE_TEXT_PRODUCT.txt +0 -119
- package/dist/cjs/index.cjs +0 -8005
- package/dist/esm/index.mjs +0 -7985
- package/src/@building/GetEventProperties.ts +0 -96
- package/src/@building/GetEventTracking.ts +0 -68
- package/src/@core/ManualEvent.ts +0 -56
- package/src/@core/SetNode.ts +0 -81
- package/src/@events/ParseAPI.ts +0 -117
- package/src/@manager/MakeEvents.ts +0 -106
- package/src/@manager/RemoveEvent.ts +0 -70
- package/src/@manager/Tasks.ts +0 -246
- package/src/@manager/ValidateEvents.ts +0 -142
- package/src/@modules/@database/InitializeDatabase.ts +0 -59
- package/src/@modules/@eas/GenerateEASMessage.ts +0 -144
- package/src/@modules/@utilities/GetFormattedTime.ts +0 -43
- package/src/@modules/@utilities/SetCronSchedule.ts +0 -94
- package/src/@modules/@utilities/SetEventEmit.ts +0 -41
- package/src/@modules/@utilities/SetListener.ts +0 -30
- package/src/@modules/@utilities/SetTimeoutAction.ts +0 -64
- package/src/@modules/@utilities/SetWarning.ts +0 -34
- package/src/@modules/@xmpp/ErrorXMPP.ts +0 -27
- package/src/@modules/@xmpp/ReconnectXMPP.ts +0 -64
- package/src/@parsers/@text/GetPolygonFromProduct.ts +0 -53
- package/src/@parsers/@text/GetXML.ts +0 -61
- package/src/@parsers/@ugc/GetCache.ts +0 -24
- package/src/@parsers/@ugc/GetZonePolygon.ts +0 -111
- package/tsup.config.ts +0 -16
|
@@ -11,14 +11,19 @@
|
|
|
11
11
|
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
12
|
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
13
|
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
-
Documentation:
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
interface SetAFSKOptions {
|
|
22
|
+
Bits: number[]
|
|
23
|
+
SampleRate: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const SetAFSK = ({ Bits, SampleRate }: SetAFSKOptions): Int16Array => {
|
|
22
27
|
const baud = 520.83;
|
|
23
28
|
const markFreq = 2083.3;
|
|
24
29
|
const spaceFreq = 1562.5;
|
|
@@ -27,20 +32,20 @@ export const SetAFSK = (bits: number[], sampleRate: number): Int16Array => {
|
|
|
27
32
|
const result = [];
|
|
28
33
|
let phase = 0;
|
|
29
34
|
let frac = 0;
|
|
30
|
-
for (let b = 0; b <
|
|
31
|
-
const bit =
|
|
35
|
+
for (let b = 0; b < Bits.length; b++) {
|
|
36
|
+
const bit = Bits[b];
|
|
32
37
|
const freq = bit ? markFreq : spaceFreq;
|
|
33
|
-
const samplesPerBit =
|
|
38
|
+
const samplesPerBit = SampleRate / baud + frac;
|
|
34
39
|
const n = Math.round(samplesPerBit);
|
|
35
40
|
frac = samplesPerBit - n;
|
|
36
|
-
const inc = twoPi * freq /
|
|
41
|
+
const inc = twoPi * freq / SampleRate;
|
|
37
42
|
for (let i = 0; i < n; i++) {
|
|
38
43
|
result.push(Math.round(Math.sin(phase) * amplitude * 32767));
|
|
39
44
|
phase += inc;
|
|
40
45
|
if (phase > twoPi) phase -= twoPi;
|
|
41
46
|
}
|
|
42
47
|
}
|
|
43
|
-
const fadeSamples = Math.floor(
|
|
48
|
+
const fadeSamples = Math.floor(SampleRate * 0.002);
|
|
44
49
|
for (let i = 0; i < fadeSamples; i++) {
|
|
45
50
|
const gain = i / fadeSamples;
|
|
46
51
|
result[i] = Math.round(result[i] * gain);
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
12
|
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
13
|
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
-
Documentation:
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
*/
|
|
@@ -11,23 +11,28 @@
|
|
|
11
11
|
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
12
|
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
13
|
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
-
Documentation:
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
interface SetAttentionToneOptions {
|
|
22
|
+
MS: number
|
|
23
|
+
SampleRate: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const SetAttentionTone = ({ MS, SampleRate }: SetAttentionToneOptions): Int16Array => {
|
|
27
|
+
const len = Math.floor(MS * SampleRate);
|
|
23
28
|
const out = new Int16Array(len);
|
|
24
29
|
const f1 = 853;
|
|
25
30
|
const f2 = 960;
|
|
26
31
|
const twoPi = Math.PI * 2;
|
|
27
32
|
const amp = 0.1;
|
|
28
|
-
const fadeLen = Math.floor(
|
|
33
|
+
const fadeLen = Math.floor(SampleRate * 0.00);
|
|
29
34
|
for (let i = 0; i < len; i++) {
|
|
30
|
-
const t = i /
|
|
35
|
+
const t = i / SampleRate;
|
|
31
36
|
const s = Math.sin(twoPi * f1 * t) + Math.sin(twoPi * f2 * t);
|
|
32
37
|
let gain = 1;
|
|
33
38
|
if (i < fadeLen) gain = i / fadeLen;
|
|
@@ -11,19 +11,24 @@
|
|
|
11
11
|
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
12
|
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
13
|
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
-
Documentation:
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import { GetPCMToFloat } from "
|
|
22
|
-
import { GetFloatPCM16 } from "
|
|
21
|
+
import { GetPCMToFloat } from "@AudioComponents/GetPCMToFloat"
|
|
22
|
+
import { GetFloatPCM16 } from "@AudioComponents/GetFloatPCM16"
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
interface SetNoiseOptions {
|
|
25
|
+
Int16: Int16Array
|
|
26
|
+
NoiseLevel?: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const SetNoise = ({ Int16, NoiseLevel }: SetNoiseOptions): Int16Array => {
|
|
30
|
+
const x = GetPCMToFloat(Int16);
|
|
31
|
+
for (let i = 0; i < x.length; i++) x[i] += (Math.random() * 2 - 1) * (NoiseLevel ?? 0.02);
|
|
27
32
|
let peak = 0;
|
|
28
33
|
for (let i = 0; i < x.length; i++) peak = Math.max(peak, Math.abs(x[i]));
|
|
29
34
|
if (peak > 1) for (let i = 0; i < x.length; i++) x[i] *= 0.98 / peak;
|
|
@@ -11,21 +11,26 @@
|
|
|
11
11
|
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
12
|
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
13
|
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
-
Documentation:
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import { GetPCMToFloat } from "
|
|
22
|
-
import { GetFloatPCM16 } from "
|
|
21
|
+
import { GetPCMToFloat } from "@AudioComponents/GetPCMToFloat"
|
|
22
|
+
import { GetFloatPCM16 } from "@AudioComponents/GetFloatPCM16"
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
interface SetRadioEffectOptions {
|
|
25
|
+
Int16: Int16Array
|
|
26
|
+
SampleRate: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const SetRadioEffect = ({ Int16, SampleRate }: SetRadioEffectOptions): Int16Array => {
|
|
25
30
|
const hpCut = 3555;
|
|
26
31
|
const lpCut = 1600;
|
|
27
|
-
const x = GetPCMToFloat(
|
|
28
|
-
const dt = 1 /
|
|
32
|
+
const x = GetPCMToFloat(Int16);
|
|
33
|
+
const dt = 1 / SampleRate;
|
|
29
34
|
const rcHP = 1 / (2 * Math.PI * hpCut);
|
|
30
35
|
const aHP = rcHP / (rcHP + dt);
|
|
31
36
|
let yHP = 0, xPrev = 0;
|
|
@@ -11,33 +11,41 @@
|
|
|
11
11
|
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
12
|
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
13
|
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
-
Documentation:
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import { SetAFSK } from "
|
|
22
|
-
import { SetAsciiToBits } from "
|
|
23
|
-
import { GetMergedPCM16 } from "
|
|
21
|
+
import { SetAFSK } from "@AudioComponents/SetAFSK"
|
|
22
|
+
import { SetAsciiToBits } from "@AudioComponents/SetAsciiToBits"
|
|
23
|
+
import { GetMergedPCM16 } from "@AudioComponents/GetMergedPCM16"
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
interface SetSameHeaderOptions {
|
|
26
|
+
VTEC: string
|
|
27
|
+
Repeats: number
|
|
28
|
+
SampleRate?: number
|
|
29
|
+
PreMarkSec?: number
|
|
30
|
+
GapSec?: number
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const SetSameHeader = ({ VTEC, Repeats, SampleRate, PreMarkSec, GapSec }: SetSameHeaderOptions): Int16Array => {
|
|
34
|
+
const preMarkSec = PreMarkSec ?? 0.3;
|
|
35
|
+
const gapSec = GapSec ?? 0.1;
|
|
28
36
|
const bursts = [];
|
|
29
|
-
const gap = new Int16Array(Math.floor(gapSec *
|
|
30
|
-
for (let i = 0; i <
|
|
31
|
-
const bodyBits = SetAsciiToBits(
|
|
32
|
-
const body = SetAFSK(bodyBits,
|
|
33
|
-
const extendedBodyDuration = Math.round(preMarkSec *
|
|
37
|
+
const gap = new Int16Array(Math.floor(gapSec * SampleRate));
|
|
38
|
+
for (let i = 0; i < Repeats; i++) {
|
|
39
|
+
const bodyBits = SetAsciiToBits(VTEC);
|
|
40
|
+
const body = SetAFSK({ Bits: bodyBits, SampleRate: SampleRate});
|
|
41
|
+
const extendedBodyDuration = Math.round(preMarkSec * SampleRate);
|
|
34
42
|
const extendedBody = new Int16Array(extendedBodyDuration + gap.length);
|
|
35
43
|
for (let j = 0; j < extendedBodyDuration; j++) {
|
|
36
44
|
extendedBody[j] = Math.round(body[j % body.length] * 0.2);
|
|
37
45
|
}
|
|
38
46
|
extendedBody.set(gap, extendedBodyDuration);
|
|
39
47
|
bursts.push(extendedBody);
|
|
40
|
-
if (i !==
|
|
48
|
+
if (i !== Repeats - 1) bursts.push(gap);
|
|
41
49
|
}
|
|
42
50
|
return GetMergedPCM16(bursts);
|
|
43
51
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { Bootstrap } from "@Bootstrap"
|
|
21
|
+
import { SetWarning } from "@Utilities/SetWarning"
|
|
22
|
+
|
|
23
|
+
interface CreateQueryOptions {
|
|
24
|
+
Query: string
|
|
25
|
+
Parameters?: unknown[]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const CreateQuery = function({ Query, Parameters }: CreateQueryOptions): any {
|
|
29
|
+
try {
|
|
30
|
+
const parameters = Array.isArray(Parameters) ? Parameters : [];
|
|
31
|
+
const statement = Bootstrap?.Database?.prepare(Query);
|
|
32
|
+
return /^\s*select/i.test(Query)
|
|
33
|
+
? statement?.all(...parameters)
|
|
34
|
+
: statement?.run(...parameters);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
SetWarning({Message: `Database Query Error: ${error instanceof Error ? error.stack ?? error.message : String(error)}`})
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { TypeSettings } from "TypesStandard/Settings"
|
|
21
|
+
import { Bootstrap } from "@Bootstrap"
|
|
22
|
+
import { SetWarning } from "@Utilities/SetWarning"
|
|
23
|
+
import { Shapefiles } from "@DatabaseImports/Shapefiles"
|
|
24
|
+
import { Broadcastify } from "@DatabaseImports/Broadcastify"
|
|
25
|
+
import { Boundaries } from "@DatabaseImports/Boundaires"
|
|
26
|
+
import { Census } from "@DatabaseImports/Census"
|
|
27
|
+
import { CreateQuery } from "@Database/CreateQuery"
|
|
28
|
+
import { existsSync, writeFileSync } from "fs"
|
|
29
|
+
import sqlite3 from "better-sqlite3"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export const InitializeDatabase = async (): Promise<void> => {
|
|
33
|
+
const settings = Bootstrap.Settings as TypeSettings;
|
|
34
|
+
try {
|
|
35
|
+
if (!existsSync(settings.Database)) {
|
|
36
|
+
writeFileSync(settings.Database, '')
|
|
37
|
+
SetWarning({ Message: `Creating new database at ${settings.Database}` })
|
|
38
|
+
}
|
|
39
|
+
Bootstrap.Database = new sqlite3(settings.Database);
|
|
40
|
+
CreateQuery({ Query: `CREATE TABLE IF NOT EXISTS stanzas ( id INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT, issued TEXT, stanza TEXT )` })
|
|
41
|
+
const isNeedingShapefiles = CreateQuery({ Query: `SELECT name FROM sqlite_master WHERE type='table' AND name='shapefiles';` }) as { name: string }[];
|
|
42
|
+
const isNeedingBroadcastify = CreateQuery({ Query: `SELECT name FROM sqlite_master WHERE type='table' AND name='broadcastify';` }) as { name: string }[];
|
|
43
|
+
const isNeedingBoundaries = CreateQuery({ Query: `SELECT name FROM sqlite_master WHERE type='table' AND name='boundaries';` }) as { name: string }[];
|
|
44
|
+
const isNeedingCities = CreateQuery({ Query: `SELECT name FROM sqlite_master WHERE type='table' AND name='cities';` }) as { name: string }[];
|
|
45
|
+
|
|
46
|
+
if (isNeedingShapefiles.length === 0 || isNeedingBroadcastify.length === 0 || isNeedingBoundaries.length === 0 || isNeedingCities.length === 0) {
|
|
47
|
+
CreateQuery({ Query: `CREATE TABLE IF NOT EXISTS broadcastify ( state TEXT, county TEXT, feed TEXT, type TEXT, link TEXT)` })
|
|
48
|
+
CreateQuery({ Query: `CREATE TABLE IF NOT EXISTS shapefiles ( id, location TEXT, source TEXT, geometry TEXT )` })
|
|
49
|
+
CreateQuery({ Query: `CREATE INDEX IF NOT EXISTS idx_shapefiles_id ON shapefiles (id)` })
|
|
50
|
+
CreateQuery({ Query: `CREATE TABLE IF NOT EXISTS boundaries (id TEXT PRIMARY KEY, type TEXT NOT NULL, state TEXT, name TEXT, geometry TEXT NOT NULL );` })
|
|
51
|
+
CreateQuery({ Query: `CREATE TABLE IF NOT EXISTS cities ( id TEXT PRIMARY KEY, name TEXT, state TEXT, county TEXT, population TEXT, lat REAL NOT NULL, lon REAL NOT NULL);`});
|
|
52
|
+
SetWarning({Message: `Required database tables are currently building, please ${Bootstrap.Colors.Red}DO NOT${Bootstrap.Colors.Reset} close your terminal. The building will not finish and will remain incomplete. If you do mess up, you will need to delete ${settings.Database} and restart the application.` })
|
|
53
|
+
if (isNeedingCities.length === 0) {
|
|
54
|
+
await Census();
|
|
55
|
+
}
|
|
56
|
+
if (isNeedingBroadcastify.length === 0) {
|
|
57
|
+
await Broadcastify();
|
|
58
|
+
}
|
|
59
|
+
if (isNeedingBoundaries.length === 0) {
|
|
60
|
+
await Boundaries();
|
|
61
|
+
}
|
|
62
|
+
if (isNeedingShapefiles.length === 0) {
|
|
63
|
+
await Shapefiles();
|
|
64
|
+
}
|
|
65
|
+
SetWarning({ Message: `Database initialization complete. You may now close your terminal or continue using the application.` })
|
|
66
|
+
}
|
|
67
|
+
} catch (error: unknown) {
|
|
68
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
69
|
+
SetWarning({ Message: `An error occurred while initializing the database: ${message}` })
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { EnumStateFIPS } from "@Enums/States"
|
|
21
|
+
import { Bootstrap } from "@Bootstrap"
|
|
22
|
+
import { CreateHttp } from "@Utilities/CreateHttp"
|
|
23
|
+
import { CreateQuery } from "@Database/CreateQuery"
|
|
24
|
+
import { SetWarning } from "@Utilities/SetWarning"
|
|
25
|
+
import { feature } from "topojson-client"
|
|
26
|
+
|
|
27
|
+
type BoundaryRow = {
|
|
28
|
+
id: string
|
|
29
|
+
type: `state` | `county`
|
|
30
|
+
state: string
|
|
31
|
+
name: string
|
|
32
|
+
geometry: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const Boundaries = async (): Promise<void> => {
|
|
36
|
+
try {
|
|
37
|
+
const existing = CreateQuery({ Query: `SELECT type, COUNT(*) AS count FROM boundaries GROUP BY type`}) as { type: string, count: number }[]
|
|
38
|
+
const existingStates = existing.find(row => row.type === `state`)?.count ?? 0
|
|
39
|
+
const existingCounties = existing.find(row => row.type === `county`)?.count ?? 0
|
|
40
|
+
|
|
41
|
+
if (existingStates > 0 || existingCounties > 0) {
|
|
42
|
+
SetWarning({ Message: `Boundary database already contains ${existingStates} states and ${existingCounties} counties, skipping import` })
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const boundaries = await CreateHttp({
|
|
47
|
+
URL: Bootstrap.Settings.BoundarySettings.BoundaryDatabase,
|
|
48
|
+
Timeout: 5000
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
if (boundaries.error || !boundaries.message) {
|
|
52
|
+
SetWarning({ Message: `Failed to download boundary database` })
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let database: any
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
database = JSON.parse(boundaries.message)
|
|
60
|
+
} catch {
|
|
61
|
+
SetWarning({ Message: `Failed to parse boundary database` })
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (database?.type !== `Topology` || !database?.objects?.states || !database?.objects?.counties) {
|
|
66
|
+
SetWarning({ Message: `Boundary database is missing states or counties` })
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let states: any
|
|
71
|
+
let counties: any
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
states = feature(database, database.objects.states)
|
|
75
|
+
counties = feature(database, database.objects.counties)
|
|
76
|
+
} catch (error: unknown) {
|
|
77
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
78
|
+
SetWarning({ Message: `Failed to convert boundary database: ${message}` })
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!Array.isArray(states?.features) || !Array.isArray(counties?.features)) {
|
|
83
|
+
SetWarning({ Message: `Boundary database contains invalid state or county data` })
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const insert = `INSERT OR REPLACE INTO boundaries (id, type, state, name, geometry) VALUES (?, ?, ?, ?, ?)`
|
|
88
|
+
const stateRows: BoundaryRow[] = []
|
|
89
|
+
const countyRows: BoundaryRow[] = []
|
|
90
|
+
let skippedStates = 0
|
|
91
|
+
let skippedCounties = 0
|
|
92
|
+
|
|
93
|
+
for (const state of states.features) {
|
|
94
|
+
if (!state?.geometry || state.id === undefined || state.id === null) {
|
|
95
|
+
skippedStates++
|
|
96
|
+
continue
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const fips = String(state.id).padStart(2, `0`)
|
|
100
|
+
const abbreviation = EnumStateFIPS[fips]
|
|
101
|
+
|
|
102
|
+
if (!abbreviation) {
|
|
103
|
+
skippedStates++
|
|
104
|
+
continue
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
stateRows.push({
|
|
108
|
+
id: fips,
|
|
109
|
+
type: `state`,
|
|
110
|
+
state: abbreviation,
|
|
111
|
+
name: state.properties?.name ?? abbreviation,
|
|
112
|
+
geometry: JSON.stringify(state.geometry)
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for (const county of counties.features) {
|
|
117
|
+
if (!county?.geometry || county.id === undefined || county.id === null) {
|
|
118
|
+
skippedCounties++
|
|
119
|
+
continue
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const fips = String(county.id).padStart(5, `0`)
|
|
123
|
+
const stateFIPS = fips.slice(0, 2)
|
|
124
|
+
const abbreviation = EnumStateFIPS[stateFIPS]
|
|
125
|
+
|
|
126
|
+
if (!abbreviation) {
|
|
127
|
+
skippedCounties++
|
|
128
|
+
continue
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
countyRows.push({
|
|
132
|
+
id: fips,
|
|
133
|
+
type: `county`,
|
|
134
|
+
state: abbreviation,
|
|
135
|
+
name: county.properties?.name ?? fips,
|
|
136
|
+
geometry: JSON.stringify(county.geometry)
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
SetWarning({ Message: `Importing ${stateRows.length} states and ${countyRows.length} counties` })
|
|
141
|
+
|
|
142
|
+
const transaction = Bootstrap.Database.transaction((rows: BoundaryRow[]) => {
|
|
143
|
+
for (const row of rows) {
|
|
144
|
+
CreateQuery({
|
|
145
|
+
Query: insert,
|
|
146
|
+
Parameters: [row.id, row.type, row.state, row.name, row.geometry]
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
transaction(stateRows)
|
|
152
|
+
transaction(countyRows)
|
|
153
|
+
|
|
154
|
+
const imported = CreateQuery({ Query: `SELECT type, COUNT(*) AS count FROM boundaries GROUP BY type`}) as { type: string, count: number }[]
|
|
155
|
+
const importedStates = imported.find(row => row.type === `state`)?.count ?? 0
|
|
156
|
+
const importedCounties = imported.find(row => row.type === `county`)?.count ?? 0
|
|
157
|
+
|
|
158
|
+
if (importedStates !== stateRows.length || importedCounties !== countyRows.length) {
|
|
159
|
+
SetWarning({ Message: `Boundary import verification failed: ${importedStates} states and ${importedCounties} counties` })
|
|
160
|
+
return
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
SetWarning({ Message: `Imported ${importedStates} states and ${importedCounties} counties` })
|
|
164
|
+
} catch (error: unknown) {
|
|
165
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
166
|
+
SetWarning({ Message: `An error occurred while importing boundaries: ${message}` })
|
|
167
|
+
}
|
|
168
|
+
}
|
package/src/{@modules/@database/ImportBroadcastify.ts → components/database/imports/Broadcastify.ts}
RENAMED
|
@@ -11,44 +11,34 @@
|
|
|
11
11
|
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
12
|
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
13
|
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
-
Documentation:
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
17
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
import {
|
|
21
|
-
import { CreateHttp } from
|
|
22
|
-
import { SetWarning } from "
|
|
23
|
-
|
|
24
|
-
export const ImportBroadcastify = async (): Promise<void> => {
|
|
25
|
-
const settings = bootstrap.settings;
|
|
26
|
-
|
|
27
|
-
const isBroadcastifyImported = bootstrap.database
|
|
28
|
-
.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name='broadcastify';`)
|
|
29
|
-
.get();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (!settings.BroadcastifySettings.BroadcastifyAttachments) { return }
|
|
33
|
-
if (isBroadcastifyImported) { return }
|
|
20
|
+
import { Bootstrap } from "@Bootstrap"
|
|
21
|
+
import { CreateHttp } from "@Utilities/CreateHttp"
|
|
22
|
+
import { SetWarning } from "@Utilities/SetWarning"
|
|
23
|
+
import { CreateQuery } from "@Database/CreateQuery";
|
|
34
24
|
|
|
25
|
+
export const Broadcastify = async (): Promise<void> => {
|
|
26
|
+
const settings = Bootstrap.Settings;
|
|
35
27
|
const broadcastify = await CreateHttp({
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
URL: settings.BroadcastifySettings.BroadcastifyDatabase,
|
|
29
|
+
Timeout: 5000,
|
|
38
30
|
});
|
|
39
31
|
if (!broadcastify.error) {
|
|
40
|
-
bootstrap.database.prepare(`CREATE TABLE broadcastify ( state TEXT, county TEXT, feed TEXT, type TEXT, link TEXT);`)
|
|
41
|
-
.run();
|
|
42
32
|
const states = JSON.parse(broadcastify.message);
|
|
43
|
-
const insert =
|
|
44
|
-
const transaction =
|
|
33
|
+
const insert = `INSERT INTO broadcastify (state, county, feed, type, link) VALUES (?, ?, ?, ?, ?)`;
|
|
34
|
+
const transaction = Bootstrap.Database.transaction((rows: any[]) => {
|
|
45
35
|
for (const row of rows) {
|
|
46
|
-
insert
|
|
36
|
+
CreateQuery({ Query: insert, Parameters: row });
|
|
47
37
|
}
|
|
48
38
|
});
|
|
49
39
|
const batch: any[] = [];
|
|
50
40
|
for (const state of states) {
|
|
51
|
-
SetWarning({
|
|
41
|
+
SetWarning({ Message: `Importing ${state.counties.length} counties from ${state.state} for Broadcastify` });
|
|
52
42
|
for (const county of state.counties) {
|
|
53
43
|
const countyName = county.county;
|
|
54
44
|
for (const feed of county.feeds) {
|
|
@@ -65,6 +55,6 @@ export const ImportBroadcastify = async (): Promise<void> => {
|
|
|
65
55
|
transaction(batch);
|
|
66
56
|
}
|
|
67
57
|
if (broadcastify.error) {
|
|
68
|
-
SetWarning({
|
|
58
|
+
SetWarning({ Message: `Error importing Broadcastify data: ${broadcastify.message}` });
|
|
69
59
|
}
|
|
70
60
|
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
import { EnumStates } from "@Enums/States"
|
|
20
|
+
import { Bootstrap } from "@Bootstrap"
|
|
21
|
+
import { CreateHttp } from "@Utilities/CreateHttp"
|
|
22
|
+
import { CreateQuery } from "@Database/CreateQuery"
|
|
23
|
+
import { SetWarning } from "@Utilities/SetWarning"
|
|
24
|
+
|
|
25
|
+
interface CityRow {
|
|
26
|
+
id: string
|
|
27
|
+
name: string
|
|
28
|
+
state: string
|
|
29
|
+
county: string
|
|
30
|
+
population: number | string
|
|
31
|
+
lat: number | string
|
|
32
|
+
lon: number | string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const Census = async (): Promise<void> => {
|
|
36
|
+
const cities = await CreateHttp({
|
|
37
|
+
URL: Bootstrap.Settings.BoundarySettings.CityDatabase,
|
|
38
|
+
Timeout: 5000
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
if (cities.error || !cities.message) {
|
|
42
|
+
SetWarning({ Message: `Failed to download city database` })
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let database: unknown
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
database = JSON.parse(cities.message)
|
|
50
|
+
} catch {
|
|
51
|
+
SetWarning({ Message: `Failed to parse city database` })
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!Array.isArray(database)) {
|
|
56
|
+
SetWarning({ Message: `Failed to parse city database` })
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const StateCodes: Record<string, string> = Object.fromEntries(
|
|
61
|
+
Object.entries(EnumStates).map(([code, name]) => [name, code])
|
|
62
|
+
);
|
|
63
|
+
const insert = `INSERT INTO cities (id, name, state, county, population, lat, lon) VALUES (?, ?, ?, ?, ?, ?, ?)`
|
|
64
|
+
const cityRows: CityRow[] = []
|
|
65
|
+
for (const city of database) {
|
|
66
|
+
if (city.country != `US`) continue
|
|
67
|
+
cityRows.push({
|
|
68
|
+
id: city.id,
|
|
69
|
+
name: city.name,
|
|
70
|
+
state: StateCodes[city.admin1] ?? null,
|
|
71
|
+
county: city.admin2,
|
|
72
|
+
population: city.pop ?? null,
|
|
73
|
+
lat: city.lat,
|
|
74
|
+
lon: city.lon
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
SetWarning({ Message: `Importing ${cityRows.length} cities` })
|
|
78
|
+
const transaction = Bootstrap.Database.transaction((rows: CityRow[]) => {
|
|
79
|
+
for (const row of rows) {
|
|
80
|
+
CreateQuery({
|
|
81
|
+
Query: insert,
|
|
82
|
+
Parameters: [row.id, row.name, row.state, row.county, row.population, row.lat, row.lon]
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
transaction(cityRows)
|
|
87
|
+
}
|