Skip to content

Commit fa42853

Browse files
committed
more reusable components for events-api to use
1 parent 7f73bbc commit fa42853

File tree

4 files changed

+57
-14
lines changed

4 files changed

+57
-14
lines changed

src/Data/DataSource.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* IF YOU EDIT THIS CLASS, YOU MUST UPDATE docs/datasources.md
1515
*/
1616
abstract class DataSource {
17+
public string $pin;
1718
/** Name of where the data is coming from */
1819
public string $source;
1920
/** Name of data product */
@@ -91,4 +92,12 @@ protected function Transform(array $data, DateTimeInterface $obstime): array {
9192
return "HelioviewerEventInterface\\Translator\\$this->translator::Transform"($data, $obstime);
9293
}
9394

95+
/**
96+
* Returns the translator class name for this data source
97+
* @return string
98+
*/
99+
public function getTranslator(): string {
100+
return $this->translator;
101+
}
102+
94103
}

src/Translator/DonkiCme.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,33 @@ private function instruments(): string {
293293
return $text;
294294
}
295295

296+
public static function buildTranslatedCME(array $record): array {
297+
try {
298+
return TranslateCME($record);
299+
} catch (IgnoreCme $e) {
300+
// Create the event with null coordinates when location can't be determined
301+
$start = new DateTimeImmutable($record['startTime']);
302+
$end = $start->add(new DateInterval("P1D"));
303+
304+
$event = new HelioviewerEvent();
305+
$event->id = $record['activityID'];
306+
$event->label = "CME " . $record['activityID'];
307+
$event->short_label = "CME";
308+
$event->version = $record['catalog'] ?? null;
309+
$event->type = 'CE';
310+
$event->start = $start->format('Y-m-d H:i:s');
311+
$event->end = $end->format('Y-m-d H:i:s');
312+
$event->link = new EventLink("DONKI", "https://kauai.ccmc.gsfc.nasa.gov/DONKI/view/CME/" . $record['activityID']);
313+
$event->views = [];
314+
// Set coordinates to null when location is unknown
315+
// $event->hv_hpc_x = null;
316+
// $event->hv_hpc_y = null;
317+
318+
$event->source = $record;
319+
return (array) $event;
320+
}
321+
}
322+
296323
public static function Translate(array $data, mixed $extra): array {
297324
$groups = [
298325
[

src/Translator/DonkiFlare.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,24 @@ public function views(): array {
119119
];
120120
}
121121

122+
public static function makeEventFromRawFlare(array $flare): array {
123+
$flare = new self($flare);
124+
$event = new HelioviewerEvent();
125+
$event->id = $flare->id();
126+
$event->label = $flare->label();
127+
$event->short_label = $flare->shortLabel();
128+
$event->version = '';
129+
$event->type = 'FL';
130+
$event->start = $flare->start();
131+
$event->end = $flare->end();
132+
$event->source = $flare->flare;
133+
$event->views = $flare->views();
134+
$event->link = $flare->link();
135+
$res = (array) $event;
136+
$res['peak'] = $flare->peak();
137+
return $res;
138+
}
139+
122140

123141
public static function Translate(array $flares, mixed $extra): array {
124142
$groups = [
@@ -131,19 +149,8 @@ public static function Translate(array $flares, mixed $extra): array {
131149
];
132150
$data = &$groups[0]['data'];
133151
foreach ($flares as $flare) {
134-
$flare = new self($flare);
135-
$event = new HelioviewerEvent();
136-
$event->id = $flare->id();
137-
$event->label = $flare->label();
138-
$event->short_label = $flare->shortLabel();
139-
$event->version = '';
140-
$event->type = 'FL';
141-
$event->start = $flare->start();
142-
$event->end = $flare->end();
143-
$event->source = $flare->flare;
144-
$event->views = $flare->views();
145-
$event->link = $flare->link();
146-
array_push($data, (array) $event);
152+
$event = self::makeEventFromRawFlare($flare);
153+
array_push($data, $event);
147154
}
148155
return $groups;
149156
}

src/Util/HapiRecord.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ public function jsonSerialize(): array
8080
}
8181
return $result;
8282
}
83-
}
83+
}

0 commit comments

Comments
 (0)