@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.
Files changed (200) hide show
  1. package/.github/CHANGELOGS.md +52 -0
  2. package/.github/CODE_OF_CONDUCT.md +24 -1
  3. package/.github/CONTRIBUTING.md +22 -3
  4. package/.github/FUNDING.yaml +3 -0
  5. package/.github/LICENSE +24 -1
  6. package/.github/SECURITY.md +25 -6
  7. package/.github/docs/chapters/general-configurations.md +109 -0
  8. package/.github/docs/chapters/sources-and-attributes.md +219 -0
  9. package/README.md +56 -146
  10. package/dist/index.cjs +25333 -0
  11. package/package.json +17 -11
  12. package/pnpm-workspace.yaml +4 -0
  13. package/src/bootstrap.ts +67 -52
  14. package/src/components/audio/GenerateAudioMessage.ts +149 -0
  15. package/src/{@modules/@eas → components/audio/components}/GetCleanDescription.ts +2 -2
  16. package/src/{@modules/@eas → components/audio/components}/GetFloatPCM16.ts +2 -2
  17. package/src/{@modules/@eas → components/audio/components}/GetMergedPCM16.ts +2 -2
  18. package/src/{@modules/@eas → components/audio/components}/GetPCM16.ts +13 -8
  19. package/src/{@modules/@eas → components/audio/components}/GetPCMToFloat.ts +2 -2
  20. package/src/{@modules/@eas → components/audio/components}/GetSampledPCM16.ts +14 -8
  21. package/src/{@modules/@eas → components/audio/components}/GetTTS.ts +17 -10
  22. package/src/{@modules/@eas → components/audio/components}/GetWavPCM16.ts +7 -7
  23. package/src/{@modules/@eas → components/audio/components}/SetAFSK.ts +13 -8
  24. package/src/{@modules/@eas → components/audio/components}/SetAsciiToBits.ts +2 -2
  25. package/src/{@modules/@eas → components/audio/components}/SetAttentionTone.ts +11 -6
  26. package/src/{@modules/@eas → components/audio/components}/SetNoise.ts +12 -7
  27. package/src/{@modules/@eas → components/audio/components}/SetRadioEffect.ts +12 -7
  28. package/src/{@modules/@eas → components/audio/components}/SetSameHeader.ts +22 -14
  29. package/src/components/database/CreateQuery.ts +39 -0
  30. package/src/components/database/InitializeDatabase.ts +71 -0
  31. package/src/components/database/imports/Boundaires.ts +168 -0
  32. package/src/{@modules/@database/ImportBroadcastify.ts → components/database/imports/Broadcastify.ts} +15 -25
  33. package/src/components/database/imports/Census.ts +87 -0
  34. package/src/{@modules/@database/ImportShapefiles.ts → components/database/imports/Shapefiles.ts} +24 -27
  35. package/src/{@modules/@database/ImportStanza.ts → components/database/imports/Stanza.ts} +15 -19
  36. package/src/components/events/CreateEvents.ts +88 -0
  37. package/src/components/events/FilterEvents.ts +149 -0
  38. package/src/{@building/CreateEvent.ts → components/events/ProcessStanza.ts} +22 -24
  39. package/src/components/events/RemoveEvents.ts +74 -0
  40. package/src/{@building → components/events/components}/GetCleanedEvent.ts +2 -2
  41. package/src/{@building → components/events/components}/GetEventAttachments.ts +14 -12
  42. package/src/components/events/components/GetEventDirection.ts +28 -0
  43. package/src/{@building → components/events/components}/GetEventEnhancedName.ts +5 -8
  44. package/src/{@building → components/events/components}/GetEventGeometry.ts +19 -13
  45. package/src/{@building → components/events/components}/GetEventHeader.ts +13 -13
  46. package/src/components/events/components/GetEventMerged.ts +51 -0
  47. package/src/{@building → components/events/components}/GetEventNodes.ts +22 -20
  48. package/src/{@building → components/events/components}/GetEventOffice.ts +13 -13
  49. package/src/components/events/components/GetEventPopulation.ts +58 -0
  50. package/src/components/events/components/GetEventProperties.ts +106 -0
  51. package/src/{@building → components/events/components}/GetEventSignature.ts +9 -9
  52. package/src/{@building → components/events/components}/GetEventTags.ts +3 -3
  53. package/src/components/events/components/GetEventTheme.ts +26 -0
  54. package/src/components/events/components/GetEventTracking.ts +64 -0
  55. package/src/{@modules/@database → components/events/utilities}/GetCachedEvents.ts +18 -15
  56. package/src/{@manager → components/events/utilities}/SetHash.ts +18 -13
  57. package/src/{@manager → components/events/utilities}/UpdateEvents.ts +12 -12
  58. package/src/{@manager → components/events/utilities}/UpdateNode.ts +14 -14
  59. package/src/{@parsers/@text → components/formatting}/GetEmbededText.ts +14 -8
  60. package/src/{@parsers/@text → components/formatting}/GetStringText.ts +15 -11
  61. package/src/{@modules/@utilities → components/geometry}/GetShapeNearestPoint.ts +24 -19
  62. package/src/components/geometry/GetUnionPolygon.ts +36 -0
  63. package/src/components/images/GenerateGraphic.ts +242 -0
  64. package/src/components/images/components/CreateRectangle.ts +22 -0
  65. package/src/components/images/components/CreateText.ts +22 -0
  66. package/src/components/images/modules/CreateSVG.ts +37 -0
  67. package/src/components/images/modules/GetGeographicalBoundaries.ts +72 -0
  68. package/src/components/images/modules/GetGeographicalCities.ts +58 -0
  69. package/src/components/images/modules/GetGeographicalEvents.ts +48 -0
  70. package/src/components/images/modules/GetGeometryBounds.ts +82 -0
  71. package/src/components/images/modules/GetParsedBoundary.ts +58 -0
  72. package/src/components/images/modules/GetSVGPath.ts +53 -0
  73. package/src/components/images/modules/NormalizePolygon.ts +57 -0
  74. package/src/{@modules/@stanza → components/stanza}/GetAwipsType.ts +16 -17
  75. package/src/{@modules/@stanza → components/stanza}/ValidateStanza.ts +27 -15
  76. package/src/{@modules/@utilities → components/utilities}/CreateHttp.ts +26 -26
  77. package/src/components/utilities/EmitThread.ts +97 -0
  78. package/src/{@modules/@utilities → components/utilities}/GetLatestIssuance.ts +2 -2
  79. package/src/{@modules/@utilities → components/utilities}/GetMatched.ts +10 -5
  80. package/src/components/utilities/QueueManager.ts +70 -0
  81. package/src/{@modules/@utilities → components/utilities}/SetDebug.ts +13 -13
  82. package/src/components/utilities/SetEventEmit.ts +42 -0
  83. package/src/{@modules/@utilities → components/utilities}/SetSettings.ts +7 -7
  84. package/src/{@modules/@utilities → components/utilities}/SetSleep.ts +5 -5
  85. package/src/components/utilities/SetTimeoutAction.ts +64 -0
  86. package/src/components/utilities/SetWarning.ts +47 -0
  87. package/src/{@modules/@xmpp → components/xmpp}/DeployXMPP.ts +20 -20
  88. package/src/{@core/CreateListener.ts → components/xmpp/ErrorXMPP.ts} +8 -5
  89. package/src/{@modules/@xmpp → components/xmpp}/OfflineXMPP.ts +13 -13
  90. package/src/{@modules/@xmpp → components/xmpp}/OnlineXMPP.ts +18 -18
  91. package/src/components/xmpp/ReconnectXMPP.ts +64 -0
  92. package/src/{@modules/@xmpp → components/xmpp}/StanzaXMPP.ts +26 -26
  93. package/src/{@enums → enums}/AWIPS.ts +2 -2
  94. package/src/{@enums → enums}/Actions.ts +2 -2
  95. package/src/{@enums → enums}/Cancellation.ts +2 -2
  96. package/src/{@enums → enums}/Causes.ts +2 -2
  97. package/src/{@enums → enums}/Correlations.ts +2 -2
  98. package/src/{@enums → enums}/Enhanced.ts +4 -3
  99. package/src/{@enums → enums}/Events.ts +2 -2
  100. package/src/{@enums → enums}/Expressions.ts +3 -3
  101. package/src/{@enums → enums}/GlobalFilter.ts +2 -2
  102. package/src/{@enums → enums}/Hail.ts +2 -2
  103. package/src/{@enums → enums}/ICAO.ts +2 -2
  104. package/src/{@enums → enums}/Matches.ts +8 -3
  105. package/src/{@enums → enums}/Products.ts +2 -2
  106. package/src/{@enums → enums}/Records.ts +2 -2
  107. package/src/{@enums → enums}/Severity.ts +2 -2
  108. package/src/{@enums → enums}/Shapefiles.ts +2 -2
  109. package/src/{@enums → enums}/States.ts +68 -4
  110. package/src/{@enums → enums}/Status.ts +2 -2
  111. package/src/{@enums → enums}/Strings.ts +2 -2
  112. package/src/{@enums → enums}/Tags.ts +9 -4
  113. package/src/{@enums → enums}/Testing.ts +2 -2
  114. package/src/enums/Themes.ts +70 -0
  115. package/src/events/ParseAPI.ts +133 -0
  116. package/src/{@events → events}/ParseText.ts +24 -22
  117. package/src/{@events → events}/ParseUGC.ts +27 -26
  118. package/src/{@events → events}/ParseVTEC.ts +37 -36
  119. package/src/{@core → exports}/ClearEvents.ts +9 -9
  120. package/src/{@core → exports}/GetEvents.ts +4 -4
  121. package/src/exports/GetNearestCity.ts +45 -0
  122. package/src/{@core → exports}/GetNodes.ts +4 -4
  123. package/src/{@core → exports}/GetRandomEvent.ts +4 -4
  124. package/src/{@core → exports}/GetVersion.ts +4 -4
  125. package/src/exports/ManualEvent.ts +55 -0
  126. package/src/{@core → exports}/QueryStanza.ts +12 -11
  127. package/src/exports/SetNode.ts +100 -0
  128. package/src/{@core → exports}/StartService.ts +23 -22
  129. package/src/{@core → exports}/StopService.ts +10 -10
  130. package/src/index.ts +57 -37
  131. package/src/{@parsers/@hvtec → parsers/hvtec}/HVExtract.ts +7 -7
  132. package/src/{@parsers/@text → parsers/text}/GetDescriptionFromProduct.ts +20 -21
  133. package/src/parsers/text/GetPolygonFromProduct.ts +71 -0
  134. package/src/{@parsers/@text → parsers/text}/GetTextFromProduct.ts +12 -12
  135. package/src/parsers/ugc/GetCache.ts +24 -0
  136. package/src/{@parsers/@ugc → parsers/ugc}/GetExpiry.ts +2 -2
  137. package/src/{@parsers/@ugc/GetUGCHeader.ts → parsers/ugc/GetHeader.ts} +4 -4
  138. package/src/{@parsers/@ugc → parsers/ugc}/GetLocations.ts +10 -10
  139. package/src/parsers/ugc/GetZonePolygon.ts +73 -0
  140. package/src/{@parsers/@ugc → parsers/ugc}/GetZones.ts +3 -3
  141. package/src/{@parsers/@ugc → parsers/ugc}/SetCache.ts +13 -8
  142. package/src/{@parsers/@ugc → parsers/ugc}/UGCExtract.ts +14 -14
  143. package/src/{@parsers/@pvtec → parsers/vtec}/GetExpiry.ts +2 -2
  144. package/src/{@parsers/@pvtec → parsers/vtec}/VTECExtract.ts +17 -17
  145. package/src/tasks/CreateTasks.ts +116 -0
  146. package/src/tasks/TaskGenerateJSON.ts +34 -0
  147. package/src/tasks/TaskGenerateText.ts +34 -0
  148. package/src/tasks/TaskSendNTFY.ts +96 -0
  149. package/src/tasks/TaskSendWebhook.ts +107 -0
  150. package/src/{@types → types/event}/Attributes.ts +2 -3
  151. package/src/{@types → types/event}/Event.ts +8 -7
  152. package/src/{@types → types/event}/HVTEC.ts +2 -2
  153. package/src/{@types → types/event}/Properties.ts +17 -3
  154. package/src/{@types → types/event}/Stanza.ts +2 -2
  155. package/src/{@types → types/event}/VTEC.ts +8 -8
  156. package/src/{@types → types/standard}/Actions.ts +3 -3
  157. package/src/{@types → types/standard}/Hash.ts +5 -5
  158. package/src/{@modules/@utilities/GetSettings.ts → types/standard/Nodes.ts} +15 -7
  159. package/src/{@types → types/standard}/Settings.ts +19 -12
  160. package/src/{@types → types/standard}/StanzaCompiled.ts +15 -15
  161. package/src/{@types → types/standard}/UGC.ts +5 -5
  162. package/tools/build.js +32 -0
  163. package/tsconfig.json +32 -1
  164. package/.github/SUPPORTED_EVENTS.md +0 -370
  165. package/.github/docs/docs-functions.md +0 -30
  166. package/.github/docs/docs-general-configurations.md +0 -209
  167. package/.github/docs/docs-integrations.md +0 -37
  168. package/.github/docs/docs-listeners.md +0 -28
  169. package/.github/docs/docs-source-configuration.md +0 -218
  170. package/.github/docs/docs-technical.md +0 -50
  171. package/.github/logo.png +0 -0
  172. package/.github/samples/SAMPLE_EAS_GENERATION.wav +0 -0
  173. package/.github/samples/SAMPLE_GEOJSON.json +0 -204
  174. package/.github/samples/SAMPLE_TEXT_PRODUCT.txt +0 -119
  175. package/dist/cjs/index.cjs +0 -8005
  176. package/dist/esm/index.mjs +0 -7985
  177. package/src/@building/GetEventProperties.ts +0 -96
  178. package/src/@building/GetEventTracking.ts +0 -68
  179. package/src/@core/ManualEvent.ts +0 -56
  180. package/src/@core/SetNode.ts +0 -81
  181. package/src/@events/ParseAPI.ts +0 -117
  182. package/src/@manager/MakeEvents.ts +0 -106
  183. package/src/@manager/RemoveEvent.ts +0 -70
  184. package/src/@manager/Tasks.ts +0 -246
  185. package/src/@manager/ValidateEvents.ts +0 -142
  186. package/src/@modules/@database/InitializeDatabase.ts +0 -59
  187. package/src/@modules/@eas/GenerateEASMessage.ts +0 -144
  188. package/src/@modules/@utilities/GetFormattedTime.ts +0 -43
  189. package/src/@modules/@utilities/SetCronSchedule.ts +0 -94
  190. package/src/@modules/@utilities/SetEventEmit.ts +0 -41
  191. package/src/@modules/@utilities/SetListener.ts +0 -30
  192. package/src/@modules/@utilities/SetTimeoutAction.ts +0 -64
  193. package/src/@modules/@utilities/SetWarning.ts +0 -34
  194. package/src/@modules/@xmpp/ErrorXMPP.ts +0 -27
  195. package/src/@modules/@xmpp/ReconnectXMPP.ts +0 -64
  196. package/src/@parsers/@text/GetPolygonFromProduct.ts +0 -53
  197. package/src/@parsers/@text/GetXML.ts +0 -61
  198. package/src/@parsers/@ugc/GetCache.ts +0 -24
  199. package/src/@parsers/@ugc/GetZonePolygon.ts +0 -111
  200. 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: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
 
19
19
  */
20
20
 
21
- export const SetAFSK = (bits: number[], sampleRate: number): Int16Array => {
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 < bits.length; b++) {
31
- const bit = bits[b];
35
+ for (let b = 0; b < Bits.length; b++) {
36
+ const bit = Bits[b];
32
37
  const freq = bit ? markFreq : spaceFreq;
33
- const samplesPerBit = sampleRate / baud + frac;
38
+ const samplesPerBit = SampleRate / baud + frac;
34
39
  const n = Math.round(samplesPerBit);
35
40
  frac = samplesPerBit - n;
36
- const inc = twoPi * freq / sampleRate;
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(sampleRate * 0.002);
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: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
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: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
 
19
19
  */
20
20
 
21
- export const SetAttentionTone = (ms: number, sampleRate: number): Int16Array => {
22
- const len = Math.floor(ms * sampleRate);
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(sampleRate * 0.00);
33
+ const fadeLen = Math.floor(SampleRate * 0.00);
29
34
  for (let i = 0; i < len; i++) {
30
- const t = i / sampleRate;
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: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
 
19
19
  */
20
20
 
21
- import { GetPCMToFloat } from "./GetPCMToFloat";
22
- import { GetFloatPCM16 } from "./GetFloatPCM16";
21
+ import { GetPCMToFloat } from "@AudioComponents/GetPCMToFloat"
22
+ import { GetFloatPCM16 } from "@AudioComponents/GetFloatPCM16"
23
23
 
24
- export const SetNoise = (int16: Int16Array, noiseLevel: number = 0.02): Int16Array => {
25
- const x = GetPCMToFloat(int16);
26
- for (let i = 0; i < x.length; i++) x[i] += (Math.random() * 2 - 1) * noiseLevel;
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: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
 
19
19
  */
20
20
 
21
- import { GetPCMToFloat } from "./GetPCMToFloat";
22
- import { GetFloatPCM16 } from "./GetFloatPCM16";
21
+ import { GetPCMToFloat } from "@AudioComponents/GetPCMToFloat"
22
+ import { GetFloatPCM16 } from "@AudioComponents/GetFloatPCM16"
23
23
 
24
- export const SetRadioEffect = (int16: Int16Array, sampleRate: number): Int16Array => {
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(int16);
28
- const dt = 1 / sampleRate;
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: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
 
19
19
  */
20
20
 
21
- import { SetAFSK } from "./SetAFSK";
22
- import { SetAsciiToBits } from "./SetAsciiToBits";
23
- import { GetMergedPCM16 } from "./GetMergedPCM16";
21
+ import { SetAFSK } from "@AudioComponents/SetAFSK"
22
+ import { SetAsciiToBits } from "@AudioComponents/SetAsciiToBits"
23
+ import { GetMergedPCM16 } from "@AudioComponents/GetMergedPCM16"
24
24
 
25
- export const SetSameHeader = (vtec: string, repeats: number, sampleRate: number = 8000, options: {preMarkSec?: number, gapSec?: number} = {}): Int16Array => {
26
- const preMarkSec = options.preMarkSec ?? 0.3;
27
- const gapSec = options.gapSec ?? 0.1;
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 * sampleRate));
30
- for (let i = 0; i < repeats; i++) {
31
- const bodyBits = SetAsciiToBits(vtec);
32
- const body = SetAFSK(bodyBits, sampleRate);
33
- const extendedBodyDuration = Math.round(preMarkSec * sampleRate);
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 !== repeats - 1) bursts.push(gap);
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
+ }
@@ -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: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
14
+ Documentation: https://atmosphericx.scriptkitty.cafe/documentation
15
15
 
16
- Internal Package: @atmosx/event-product-parser
16
+ Independent Package: @atmosx/event-product-parser
17
17
 
18
18
  */
19
19
 
20
- import { bootstrap } from "../../bootstrap"
21
- import { CreateHttp } from '../@utilities/CreateHttp'
22
- import { SetWarning } from "../@utilities/SetWarning";
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
- url: settings.BroadcastifySettings.BroadcastifyDatabase,
37
- timeout: 5000,
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 = bootstrap.database.prepare(`INSERT INTO broadcastify (state, county, feed, type, link) VALUES (?, ?, ?, ?, ?)`);
44
- const transaction = bootstrap.database.transaction((rows: any[]) => {
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.run(row);
36
+ CreateQuery({ Query: insert, Parameters: row });
47
37
  }
48
38
  });
49
39
  const batch: any[] = [];
50
40
  for (const state of states) {
51
- SetWarning({ message: `Importing ${state.counties.length} counties from ${state.state} for Broadcastify` });
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({ message: `Error importing Broadcastify data: ${broadcastify.message}` });
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
+ }