Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/firebird-ng/src/app/model/event.ts is written in an unsupported language. File is not indexed.

0001 import {EventGroup, EventGroupFactory, getEventGroupFactory} from "./event-group";
0002 
0003 export class Event
0004 {
0005   id: string = "";
0006   groups: EventGroup[] = [];
0007 
0008   toDexObject(): any {
0009     const objGroups: any[] = [];
0010     for (const component of this.groups) {
0011       objGroups.push(component.toDexObject());
0012     }
0013     return {
0014       id: this.id,
0015       groups: objGroups,
0016     };
0017   }
0018 
0019   static fromDexObject(obj: any): Event {
0020     let result = new Event();
0021     result.id = obj["id"];
0022     for(const objComponent of obj["groups"]) {
0023       const compType = objComponent["type"];
0024 
0025       if(!compType) {
0026         console.warn(`A problem with entry component type (a required field). It is: '${compType}'`);
0027         continue;
0028       }
0029 
0030       const factory = getEventGroupFactory(compType);
0031       if(factory === null || factory === undefined ) {
0032         console.warn(`Can't find EventGroup factory for type name: '${compType}'`)
0033       }
0034       else {
0035         result.groups.push(factory.fromDexObject(objComponent));
0036       }
0037     }
0038     return result;
0039   }
0040 
0041   /**
0042    * Calculates the global time range across all components with valid time ranges.
0043    * @returns A tuple [minTime, maxTime] or null if no component has a valid time range.
0044    */
0045   get timeRange(): [number, number] | null {
0046     let minTime: number | null = null;
0047     let maxTime: number | null = null;
0048     let hasValidTimeRange = false;
0049 
0050     // Iterate through all components
0051     for (const component of this.groups) {
0052       const componentTimeRange = component.timeRange;
0053 
0054       // Skip components with null time range
0055       if (componentTimeRange === null) continue;
0056 
0057       const [componentMinTime, componentMaxTime] = componentTimeRange;
0058 
0059       // Initialize min/max times if this is the first valid component
0060       if (!hasValidTimeRange) {
0061         minTime = componentMinTime;
0062         maxTime = componentMaxTime;
0063         hasValidTimeRange = true;
0064         continue;
0065       }
0066 
0067       // Update min/max values
0068       if (componentMinTime < minTime!) {
0069         minTime = componentMinTime;
0070       }
0071 
0072       if (componentMaxTime > maxTime!) {
0073         maxTime = componentMaxTime;
0074       }
0075     }
0076 
0077     // Return the range if at least one component had a valid time range
0078     if (hasValidTimeRange && minTime !== null && maxTime !== null) {
0079       return [minTime, maxTime];
0080     }
0081 
0082     return null;
0083   }
0084 }