Back to home page

EIC code displayed by LXR

 
 

    


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

0001 import {Injectable} from "@angular/core";
0002 import {UserConfigService} from "./user-config.service";
0003 import {Object3D} from "three";
0004 import {defaultFirebirdConfig, ServerConfigService} from "./server-config.service";
0005 import {Entry} from "../model/entry";
0006 import {HttpClient} from "@angular/common/http";
0007 import {firstValueFrom} from "rxjs";
0008 import {UrlService} from "./url.service";
0009 import {DataExchange} from "../model/data-exchange";
0010 import {fetchTextFile, loadJSONFileEvents, loadZipFileEvents} from "../utils/data-fetching.utils";
0011 
0012 @Injectable({
0013   providedIn: 'root'
0014 })
0015 export class DataModelService {
0016 
0017   public currentEvent: Entry|null = null;
0018 
0019   constructor(private userConfig: UserConfigService,
0020               private serverConfig: ServerConfigService,
0021               private urlService: UrlService,
0022               private http: HttpClient
0023               ) {
0024   }
0025 
0026 
0027   async loadEdm4EicData(entryNames: string = "0"): Promise<DataExchange|null> {
0028     try {
0029 
0030       let userInput = this.userConfig.edm4eicEventSource.value;
0031       // TODO url aliases if(this.serverConfig.config.)
0032       // resolveProtocolAlias()
0033 
0034       if(!userInput) {
0035         console.log("[DataModelService] No data source specified. I.e. !this.userConfig.edm4eicEventSource.value");
0036         return null;
0037       }
0038 
0039       // If we were able to get baseURL, we use it with endpoint
0040       // Otherwise we just open whatever...
0041       let url = this.urlService.resolveConvertUrl(userInput, "edm4eic", entryNames);
0042 
0043 
0044       // // if no protocol specified, assume local
0045       // if(!userInput.includes('://')) {
0046       //   userInput = "local://" + userInput;
0047       // }
0048       //
0049       // if(userInput.startsWith("local://")) {
0050       //   userInput = this.urlService.resolveLocalhostUrl(userInput);
0051       // }
0052 
0053       const jsonData = await fetchTextFile(url);
0054       //   //this.http.get(url, { responseType: 'text' })
0055       // );
0056 
0057 
0058 
0059       const dexData = JSON.parse(jsonData);
0060       let data = DataExchange.fromDexObj(dexData);
0061 
0062       console.log(data)
0063       return data;
0064     } catch (error) {
0065       console.error(`Failed to load data: ${error}`);
0066       console.log(`Default config will be used`);
0067     } finally {
0068     }
0069     return null;
0070   }
0071 
0072 
0073   async loadDexData(): Promise<DataExchange|null> {
0074     try {
0075 
0076       let userInput = this.userConfig.trajectoryEventSource.value;
0077       // TODO url aliases if(this.serverConfig.config.)
0078       // resolveProtocolAlias()
0079 
0080       if(!userInput) {
0081         console.log("[DataModelService] No data source specified. I.e. !this.userConfig.edm4eicEventSource.value");
0082         return null;
0083       }
0084 
0085       if(!userInput.endsWith("firebird.json") &&
0086          !userInput.endsWith("firebird.json.zip") &&
0087          !userInput.endsWith("firebird.zip"))
0088       {
0089         console.log("[DataModelService.loadDexData] Wrong extension. I.e. !this.userConfig.edm4eicEventSource.value");
0090       }
0091 
0092       let url = this.urlService.resolveDownloadUrl(userInput);
0093 
0094       let dexData = {};
0095 
0096       if(url.endsWith("zip")) {
0097         dexData = await loadZipFileEvents(url);
0098       } else {
0099         dexData = await loadJSONFileEvents(url);
0100       }
0101 
0102       let data = DataExchange.fromDexObj(dexData);
0103 
0104       console.log(data)
0105       return data;
0106     } catch (error) {
0107       console.error(`Failed to load data: ${error}`);
0108       console.log(`Default config will be used`);
0109     } finally {
0110     }
0111     return null;
0112   }
0113 }