data.dart 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:archive/archive_io.dart';
  4. import 'package:jiffy/jiffy.dart';
  5. import 'package:myshelf/models/dtinterval.dart';
  6. import 'package:supabase/supabase.dart';
  7. final Map<String, String> tables = {
  8. "secondprgtype.txt": "aclegs_csv",
  9. "ExportPGRGPNmois.txt": "pnlegs_csv",
  10. "exportPGRGPN.txt": "pnlegs_csv",
  11. "exportlicence.txt": "licences_csv",
  12. };
  13. final Map<String, List<String>> headers = {
  14. "secondprgtype.txt": [
  15. "leg_no",
  16. "fn_carrier",
  17. "fn_number",
  18. "fn_suffix",
  19. "day_of_origin",
  20. "ac_owner",
  21. "ac_subtype",
  22. "ac_version",
  23. "ac_registration",
  24. "dep_ap_actual",
  25. "dep_ap_sched",
  26. "dep_dt_est",
  27. "dep_sched_dt",
  28. "arr_ap_actual",
  29. "arr_ap_sched",
  30. "arr_dt_est",
  31. "arr_sched_dt",
  32. "slot_time_actual",
  33. "leg_type",
  34. "status",
  35. "employer_cockpit",
  36. "employer_cabin",
  37. "cycles",
  38. "delay_code_01",
  39. "delay_code_02",
  40. "delay_code_03",
  41. "delay_code_04",
  42. "delay_time_01",
  43. "delay_time_02",
  44. "delay_time_03",
  45. "delay_time_04",
  46. "subdelay_code_01",
  47. "subdelay_code_02",
  48. "subdelay_code_03",
  49. "subdelay_code_04",
  50. "pax_booked_c",
  51. "pax_booked_y",
  52. "pax_booked_trs_c",
  53. "pax_booked_trs_y",
  54. "pad_booked_c",
  55. "pad_booked_y",
  56. "offblock_dt_a",
  57. "airborne_dt_a",
  58. "landing_dt_a",
  59. "onblock_dt_a",
  60. "offblock_dt_f",
  61. "airborne_dt_f",
  62. "landing_dt_f",
  63. "onblock_dt_f",
  64. "offblock_dt_m",
  65. "airborne_dt_m",
  66. "landing_dt_m",
  67. "onblock_dt_m",
  68. "eet",
  69. ],
  70. "exportPGRGPN.txt": [
  71. "date",
  72. "tlc",
  73. "actype",
  74. "al",
  75. "fnum",
  76. "ddep",
  77. "hdep",
  78. "ddes",
  79. "hdes",
  80. "dep",
  81. "des",
  82. "label",
  83. "type",
  84. ],
  85. "ExportPGRGPNmois.txt": [
  86. "date",
  87. "tlc",
  88. "actype",
  89. "al",
  90. "fnum",
  91. "ddep",
  92. "hdep",
  93. "ddes",
  94. "hdes",
  95. "dep",
  96. "des",
  97. "label",
  98. "type",
  99. ],
  100. "exportlicence.txt": [
  101. "tlc",
  102. "fname",
  103. "mname",
  104. "lname",
  105. "expire",
  106. "ac",
  107. "college",
  108. "base",
  109. ],
  110. };
  111. final Map<String, String> scopes = {
  112. "secondprgtype.txt": "day_of_origin",
  113. "exportPGRGPN.txt": "date",
  114. "ExportPGRGPNmois.txt": "date",
  115. "exportlicence.txt": "tlc",
  116. };
  117. final Map<String, List<String>> idToRemove = {
  118. "secondprgtype.txt": ["day_of_origin"],
  119. "exportPGRGPN.txt": ["date", "tlc"],
  120. "ExportPGRGPNmois.txt": ["date", "tlc"],
  121. "exportlicence.txt": ["tlc"],
  122. };
  123. final Map<String, Map<String, dynamic>> ids = {
  124. "secondprgtype.txt": {
  125. "table": "aclegs_log",
  126. "headers": [
  127. "day_of_origin",
  128. "dep_sched_dt",
  129. "fn_carrier",
  130. "fn_number",
  131. "dep_ap_sched",
  132. "arr_ap_sched",
  133. // "dep_ap_actual",
  134. // "arr_ap_actual"
  135. ]
  136. },
  137. "exportPGRGPN.txt": {
  138. "table": "pnlegs_log",
  139. "headers": ["tlc", "date", "dep", "des", "al", "fnum,", "label"]
  140. },
  141. "ExportPGRGPNmois.txt": {
  142. "table": "pnlegs_log",
  143. "headers": ["tlc", "date", "dep", "des", "al", "fnum,", "label"]
  144. },
  145. "exportlicence.txt": {
  146. "table": "qualifs_log",
  147. "headers": ["tlc", "college", "ac", "base"]
  148. },
  149. };
  150. List<Map<String, String?>> createListOfMaps(
  151. List<String> headers, List<List<dynamic>> data) {
  152. // Initialize an empty list to hold the maps
  153. List<Map<String, String?>> result = [];
  154. // Iterate over each row of data
  155. for (var row in data) {
  156. // Create a map for the current row
  157. Map<String, String?> map = {};
  158. // Populate the map with header-value pairs
  159. for (int i = 0; i < headers.length; i++) {
  160. if (i < row.length) {
  161. // Convert each value to String? and handle null values
  162. map[headers[i]] = row[i]
  163. ?.toString(); // Use toString() to ensure it's a String or null
  164. } else {
  165. // If there's no corresponding data, set it as null
  166. map[headers[i]] = null;
  167. }
  168. }
  169. // Add the map to the result list
  170. result.add(map);
  171. }
  172. return result;
  173. }
  174. List<List<String?>> csv2list(String text,
  175. {bool nulling = true, bool quotes = true, bool trim = true}) {
  176. List<List<String?>> out = [];
  177. final lines = text.split("\n");
  178. for (var line in lines) {
  179. final cols = line.split(",").map((String? e) {
  180. if (e != null && quotes) {
  181. e = e.replaceAll('"', "");
  182. }
  183. if (e != null && trim) {
  184. e = e.trim();
  185. }
  186. if (nulling) {
  187. e = (e == "") ? null : e;
  188. }
  189. return e;
  190. }).toList();
  191. // print("${out.length}: $cols");
  192. if (cols.isNotEmpty && cols.length > 1) out.add(cols);
  193. }
  194. return out;
  195. }
  196. class Qualif {
  197. String? tlc;
  198. String? lname;
  199. String? mname;
  200. String? fname;
  201. String? date;
  202. String? ac;
  203. String? college;
  204. String? base;
  205. Qualif({
  206. this.tlc,
  207. this.lname,
  208. this.mname,
  209. this.fname,
  210. this.date,
  211. this.ac,
  212. this.college,
  213. this.base,
  214. });
  215. Qualif copyWith({
  216. String? tlc,
  217. String? lname,
  218. String? mname,
  219. String? fname,
  220. String? date,
  221. String? ac,
  222. String? college,
  223. String? base,
  224. }) {
  225. return Qualif(
  226. tlc: tlc ?? this.tlc,
  227. lname: lname ?? this.lname,
  228. mname: mname ?? this.mname,
  229. fname: fname ?? this.fname,
  230. date: date ?? this.date,
  231. ac: ac ?? this.ac,
  232. college: college ?? this.college,
  233. base: base ?? this.base,
  234. );
  235. }
  236. Map<String, dynamic> toMap() {
  237. return <String, dynamic>{
  238. 'tlc': tlc,
  239. 'lname': lname,
  240. 'mname': mname,
  241. 'fname': fname,
  242. 'date': date,
  243. 'ac': ac,
  244. 'college': college,
  245. 'base': base,
  246. };
  247. }
  248. factory Qualif.fromList(List datalist) {
  249. return Qualif(
  250. tlc: datalist[0],
  251. lname: datalist[1],
  252. mname: datalist[2],
  253. fname: datalist[3],
  254. date: datalist[4],
  255. ac: datalist[5],
  256. college: datalist[6],
  257. base: datalist[7]);
  258. }
  259. factory Qualif.fromMap(Map<String, dynamic> map) {
  260. return Qualif(
  261. tlc: map['tlc'] != null ? map['tlc'] as String : null,
  262. lname: map['lname'] != null ? map['lname'] as String : null,
  263. mname: map['mname'] != null ? map['mname'] as String : null,
  264. fname: map['fname'] != null ? map['fname'] as String : null,
  265. date: map['date'] != null ? map['date'] as String : null,
  266. ac: map['ac'] != null ? map['ac'] as String : null,
  267. college: map['college'] != null ? map['college'] as String : null,
  268. base: map['base'] != null ? map['base'] as String : null,
  269. );
  270. }
  271. String toJson() => json.encode(toMap());
  272. factory Qualif.fromJson(String source) =>
  273. Qualif.fromMap(json.decode(source) as Map<String, dynamic>);
  274. @override
  275. String toString() {
  276. return 'Qualif(tlc: $tlc, lname: $lname, mname: $mname, fname: $fname, date: $date, ac: $ac, college: $college, base: $base)';
  277. }
  278. @override
  279. bool operator ==(covariant Qualif other) {
  280. if (identical(this, other)) return true;
  281. return other.tlc == tlc &&
  282. other.lname == lname &&
  283. other.mname == mname &&
  284. other.fname == fname &&
  285. other.date == date &&
  286. other.ac == ac &&
  287. other.college == college &&
  288. other.base == base;
  289. }
  290. @override
  291. int get hashCode {
  292. return tlc.hashCode ^
  293. lname.hashCode ^
  294. mname.hashCode ^
  295. fname.hashCode ^
  296. date.hashCode ^
  297. ac.hashCode ^
  298. college.hashCode ^
  299. base.hashCode;
  300. }
  301. }
  302. class Pnleg {
  303. String? date;
  304. Jiffy? get jdate => date != null
  305. ? Jiffy.parse(date ?? "01/01/1970", pattern: "dd/MM/yyyy", isUtc: true)
  306. : null;
  307. String? tlc;
  308. String? actype;
  309. String? al;
  310. String? fnum;
  311. String? depdate;
  312. String? deptime;
  313. String? arrdate;
  314. String? arrtime;
  315. String? dep;
  316. String? arr;
  317. String? label;
  318. String? type;
  319. Jiffy? get jdep =>
  320. deptime != null ? "$depdate $deptime".parseddmmyyyyhhmm() : null;
  321. Jiffy? get jarr =>
  322. arrtime != null ? "$arrdate $arrtime".parseddmmyyyyhhmm() : null;
  323. String get dutytype {
  324. if (type == "L") {
  325. return "flight";
  326. } else if ((type == "G")) {
  327. return "dhlimo";
  328. } else if ((type == "F") || ((dep ?? "") != "" && (arr ?? "") != "")) {
  329. return "dhflight";
  330. } else if ((label?.startsWith("SBY") ?? false) || (label == "R0")) {
  331. return "standby";
  332. } else if ((!["OFF", "CM", "CA", "PP"].contains(label)) &&
  333. (jarr != null &&
  334. jdep != null &&
  335. DTInterval(jdep!, jarr!).duration.inHours < 18)) {
  336. return "ground";
  337. } else {
  338. return "day";
  339. }
  340. }
  341. Pnleg({
  342. this.date,
  343. this.tlc,
  344. this.actype,
  345. this.al,
  346. this.fnum,
  347. this.depdate,
  348. this.deptime,
  349. this.arrdate,
  350. this.arrtime,
  351. this.dep,
  352. this.arr,
  353. this.label,
  354. this.type,
  355. });
  356. Pnleg copyWith({
  357. String? date,
  358. String? tlc,
  359. String? actype,
  360. String? al,
  361. String? fnum,
  362. String? depdate,
  363. String? deptime,
  364. String? arrdate,
  365. String? arrtime,
  366. String? dep,
  367. String? arr,
  368. String? label,
  369. String? type,
  370. }) {
  371. return Pnleg(
  372. date: date ?? this.date,
  373. tlc: tlc ?? this.tlc,
  374. actype: actype ?? this.actype,
  375. al: al ?? this.al,
  376. fnum: fnum ?? this.fnum,
  377. depdate: depdate ?? this.depdate,
  378. deptime: deptime ?? this.deptime,
  379. arrdate: arrdate ?? this.arrdate,
  380. arrtime: arrtime ?? this.arrtime,
  381. dep: dep ?? this.dep,
  382. arr: arr ?? this.arr,
  383. label: label ?? this.label,
  384. type: type ?? this.type,
  385. );
  386. }
  387. Map<String, dynamic> toMap() {
  388. return <String, dynamic>{
  389. 'date': date,
  390. 'tlc': tlc,
  391. 'actype': actype,
  392. 'al': al,
  393. 'fnum': fnum,
  394. 'depdate': depdate,
  395. 'deptime': deptime,
  396. 'arrdate': arrdate,
  397. 'arrtime': arrtime,
  398. 'dep': dep,
  399. 'arr': arr,
  400. 'label': label,
  401. 'type': type,
  402. };
  403. }
  404. factory Pnleg.fromList(List datalist) {
  405. return Pnleg(
  406. date: datalist[0],
  407. tlc: datalist[1],
  408. actype: datalist[2],
  409. al: datalist[3],
  410. fnum: datalist[4],
  411. depdate: datalist[5],
  412. deptime: datalist[6],
  413. arrdate: datalist[7],
  414. arrtime: datalist[8],
  415. dep: datalist[9],
  416. arr: datalist[10],
  417. label: datalist[11],
  418. type: datalist[12]);
  419. }
  420. factory Pnleg.fromMap(Map<String, dynamic> map) {
  421. return Pnleg(
  422. date: map['date'] != null ? map['date'] as String : null,
  423. tlc: map['tlc'] != null ? map['tlc'] as String : null,
  424. actype: map['actype'] != null ? map['actype'] as String : null,
  425. al: map['al'] != null ? map['al'] as String : null,
  426. fnum: map['fnum'] != null ? map['fnum'] as String : null,
  427. depdate: map['depdate'] != null ? map['depdate'] as String : null,
  428. deptime: map['deptime'] != null ? map['deptime'] as String : null,
  429. arrdate: map['arrdate'] != null ? map['arrdate'] as String : null,
  430. arrtime: map['arrtime'] != null ? map['arrtime'] as String : null,
  431. dep: map['dep'] != null ? map['dep'] as String : null,
  432. arr: map['arr'] != null ? map['arr'] as String : null,
  433. label: map['label'] != null ? map['label'] as String : null,
  434. type: map['type'] != null ? map['type'] as String : null,
  435. );
  436. }
  437. String toJson() => json.encode(toMap());
  438. factory Pnleg.fromJson(String source) =>
  439. Pnleg.fromMap(json.decode(source) as Map<String, dynamic>);
  440. @override
  441. String toString() {
  442. return 'Pnleg(date: $date, tlc: $tlc, actype: $actype, al: $al, fnum: $fnum, depdate: $depdate, deptime: $deptime, arrdate: $arrdate, arrtime: $arrtime, dep: $dep, arr: $arr, label: $label, type: $type)';
  443. }
  444. @override
  445. bool operator ==(covariant Pnleg other) {
  446. if (identical(this, other)) return true;
  447. return other.date == date &&
  448. other.tlc == tlc &&
  449. other.actype == actype &&
  450. other.al == al &&
  451. other.fnum == fnum &&
  452. other.depdate == depdate &&
  453. other.deptime == deptime &&
  454. other.arrdate == arrdate &&
  455. other.arrtime == arrtime &&
  456. other.dep == dep &&
  457. other.arr == arr &&
  458. other.label == label &&
  459. other.type == type;
  460. }
  461. @override
  462. int get hashCode {
  463. return date.hashCode ^
  464. tlc.hashCode ^
  465. actype.hashCode ^
  466. al.hashCode ^
  467. fnum.hashCode ^
  468. depdate.hashCode ^
  469. deptime.hashCode ^
  470. arrdate.hashCode ^
  471. arrtime.hashCode ^
  472. dep.hashCode ^
  473. arr.hashCode ^
  474. label.hashCode ^
  475. type.hashCode;
  476. }
  477. }
  478. //enum flt_status { sched, delayed, taxiout, enroute, landed, arrived }
  479. class Acleg {
  480. String? LEG_NO;
  481. String? FN_CARRIER;
  482. String? FN_NUMBER;
  483. String? FN_SUFFIX;
  484. String? DAY_OF_ORIGIN;
  485. String? AC_OWNER;
  486. String? AC_SUBTYPE;
  487. String? AC_VERSION;
  488. String? AC_REGISTRATION;
  489. String? DEP_AP_ACTUAL;
  490. String? DEP_AP_SCHED;
  491. String? DEP_DT_EST;
  492. Jiffy? get jdepest =>
  493. (DEP_DT_EST == null) ? null : DEP_DT_EST!.parseyyyymmddhhmm();
  494. String? DEP_SCHED_DT;
  495. Jiffy? get jdepsched =>
  496. (DEP_SCHED_DT == null) ? null : DEP_SCHED_DT!.parseyyyymmddhhmm();
  497. String? ARR_AP_ACTUAL;
  498. String? ARR_AP_SCHED;
  499. String? ARR_DT_EST;
  500. Jiffy? get jarrest =>
  501. (ARR_DT_EST == null) ? null : ARR_DT_EST!.parseyyyymmddhhmm();
  502. String? ARR_SCHED_DT;
  503. Jiffy? get jarrsched =>
  504. (ARR_SCHED_DT == null) ? null : ARR_SCHED_DT!.parseyyyymmddhhmm();
  505. String? SLOT_TIME_ACTUAL;
  506. Jiffy? get slot =>
  507. (SLOT_TIME_ACTUAL == null) ? null : SLOT_TIME_ACTUAL!.parseyyyymmddhhmm();
  508. String? LEG_TYPE;
  509. String? STATUS;
  510. String? EMPLOYER_COCKPIT;
  511. String? EMPLOYER_CABIN;
  512. String? CYCLES;
  513. String? DELAY_CODE_01;
  514. String? DELAY_CODE_02;
  515. String? DELAY_CODE_03;
  516. String? DELAY_CODE_04;
  517. String? DELAY_TIME_01;
  518. String? DELAY_TIME_02;
  519. String? DELAY_TIME_03;
  520. String? DELAY_TIME_04;
  521. String? SUBDELAY_CODE_01;
  522. String? SUBDELAY_CODE_02;
  523. String? SUBDELAY_CODE_03;
  524. String? SUBDELAY_CODE_04;
  525. List<List> get dla => [
  526. [
  527. SUBDELAY_CODE_01 ?? DELAY_CODE_01,
  528. DELAY_TIME_01 == null
  529. ? null
  530. : Duration(minutes: int.parse(DELAY_TIME_01!))
  531. ],
  532. [
  533. SUBDELAY_CODE_02 ?? DELAY_CODE_02,
  534. DELAY_TIME_02 == null
  535. ? null
  536. : Duration(minutes: int.parse(DELAY_TIME_02!))
  537. ],
  538. [
  539. SUBDELAY_CODE_03 ?? DELAY_CODE_03,
  540. DELAY_TIME_03 == null
  541. ? null
  542. : Duration(minutes: int.parse(DELAY_TIME_03!))
  543. ],
  544. [
  545. SUBDELAY_CODE_04 ?? DELAY_CODE_04,
  546. DELAY_TIME_04 == null
  547. ? null
  548. : Duration(minutes: int.parse(DELAY_TIME_04!))
  549. ],
  550. ].where((e) => e.every((f) => f != null)).toList();
  551. List<String> get delaycode => [
  552. DELAY_CODE_01,
  553. DELAY_CODE_02,
  554. DELAY_CODE_03,
  555. DELAY_CODE_04
  556. ].nonNulls.toList();
  557. List<String> get delaysubcode => [
  558. SUBDELAY_CODE_01,
  559. SUBDELAY_CODE_02,
  560. SUBDELAY_CODE_03,
  561. SUBDELAY_CODE_04
  562. ].nonNulls.toList();
  563. List<Duration?> get delaytime => [
  564. DELAY_TIME_01 == null
  565. ? null
  566. : Duration(minutes: int.parse(DELAY_TIME_01!)),
  567. DELAY_TIME_02 == null
  568. ? null
  569. : Duration(minutes: int.parse(DELAY_TIME_02!)),
  570. DELAY_TIME_03 == null
  571. ? null
  572. : Duration(minutes: int.parse(DELAY_TIME_03!)),
  573. DELAY_TIME_04 == null
  574. ? null
  575. : Duration(minutes: int.parse(DELAY_TIME_04!))
  576. ].nonNulls.toList();
  577. String? PAX_BOOKED_C;
  578. String? PAX_BOOKED_Y;
  579. String? get pax_booked => (PAX_BOOKED_C != null || PAX_BOOKED_Y != null)
  580. ? "${(AC_VERSION != null && AC_VERSION!.contains("C")) ? "C${PAX_BOOKED_C ?? 0}." : ""}Y${PAX_BOOKED_Y ?? 0}"
  581. : null;
  582. String? PAX_BOOKED_TRS_C;
  583. String? PAX_BOOKED_TRS_Y;
  584. String? get pax_trs => (PAX_BOOKED_TRS_C != null || PAX_BOOKED_TRS_Y != null)
  585. ? "C${PAX_BOOKED_TRS_C ?? 0}/Y${PAX_BOOKED_TRS_Y ?? 0}"
  586. : null;
  587. String? PAD_BOOKED_C;
  588. String? PAD_BOOKED_Y;
  589. String? get pad_booked => (PAD_BOOKED_C != null || PAD_BOOKED_Y != null)
  590. ? "C${PAD_BOOKED_C ?? 0}/Y${PAD_BOOKED_Y ?? 0}"
  591. : null;
  592. String? OFFBLOCK_DT_A;
  593. String? AIRBORNE_DT_A;
  594. String? LANDING_DT_A;
  595. String? ONBLOCK_DT_A;
  596. List<Jiffy?> get blocks_a => [
  597. (OFFBLOCK_DT_A ?? "").parseyyyymmddhhmm(),
  598. (AIRBORNE_DT_A ?? "").parseyyyymmddhhmm(),
  599. (LANDING_DT_A ?? "").parseyyyymmddhhmm(),
  600. (ONBLOCK_DT_A ?? "").parseyyyymmddhhmm()
  601. ];
  602. String get flt_status {
  603. if (blocks[3] != null) {
  604. return "Arrived";
  605. } else if (blocks[2] != null) {
  606. return "Landed";
  607. } else if (blocks[1] != null) {
  608. return "Inflight";
  609. } else if (blocks[0] != null) {
  610. return "Taxiout";
  611. } else if (jdepest != null &&
  612. jarrsched != null &&
  613. jdepest!.isAfter(jdepsched!)) {
  614. return "Delayed";
  615. } else {
  616. return "Sched";
  617. }
  618. }
  619. String? OFFBLOCK_DT_F;
  620. String? AIRBORNE_DT_F;
  621. String? LANDING_DT_F;
  622. String? ONBLOCK_DT_F;
  623. List<Jiffy?> get blocks_f => [
  624. (OFFBLOCK_DT_F ?? "").parseyyyymmddhhmm(),
  625. (AIRBORNE_DT_F ?? "").parseyyyymmddhhmm(),
  626. (LANDING_DT_F ?? "").parseyyyymmddhhmm(),
  627. (ONBLOCK_DT_F ?? "").parseyyyymmddhhmm()
  628. ];
  629. String? OFFBLOCK_DT_M;
  630. String? AIRBORNE_DT_M;
  631. String? LANDING_DT_M;
  632. String? ONBLOCK_DT_M;
  633. List<Jiffy?> get blocks_m => [
  634. (OFFBLOCK_DT_M ?? "").parseyyyymmddhhmm(),
  635. (AIRBORNE_DT_M ?? "").parseyyyymmddhhmm(),
  636. (LANDING_DT_M ?? "").parseyyyymmddhhmm(),
  637. (ONBLOCK_DT_M ?? "").parseyyyymmddhhmm()
  638. ];
  639. List<Jiffy?> get blocks => [
  640. blocks_m[0] ?? blocks_a[0] ?? blocks_f[0],
  641. blocks_m[1] ?? blocks_a[1] ?? blocks_f[1],
  642. blocks_m[2] ?? blocks_a[2] ?? blocks_f[2],
  643. blocks_m[3] ?? blocks_a[3] ?? blocks_f[3]
  644. ];
  645. Jiffy? get jdep => blocks[0] ?? jdepest ?? jdepsched;
  646. Jiffy? get jarr =>
  647. blocks[3] ??
  648. blocks[2]?.add(minutes: 5) ??
  649. (eet == null ? null : blocks[1]?.addDuration(eet!).add(minutes: 8)) ??
  650. (eet == null
  651. ? null
  652. : blocks[0]?.add(minutes: 5).addDuration(eet!).add(minutes: 8)) ??
  653. (eet == null
  654. ? null
  655. : jdep?.addDuration(eet!).add(minutes: 8).add(minutes: 5)) ??
  656. jarrest ??
  657. jarrsched;
  658. String? EET;
  659. Duration? get eet => EET == null ? null : Duration(minutes: int.parse(EET!));
  660. Acleg({
  661. this.LEG_NO,
  662. this.FN_CARRIER,
  663. this.FN_NUMBER,
  664. this.FN_SUFFIX,
  665. this.DAY_OF_ORIGIN,
  666. this.AC_OWNER,
  667. this.AC_SUBTYPE,
  668. this.AC_VERSION,
  669. this.AC_REGISTRATION,
  670. this.DEP_AP_ACTUAL,
  671. this.DEP_AP_SCHED,
  672. this.DEP_DT_EST,
  673. this.DEP_SCHED_DT,
  674. this.ARR_AP_ACTUAL,
  675. this.ARR_AP_SCHED,
  676. this.ARR_DT_EST,
  677. this.ARR_SCHED_DT,
  678. this.SLOT_TIME_ACTUAL,
  679. this.LEG_TYPE,
  680. this.STATUS,
  681. this.EMPLOYER_COCKPIT,
  682. this.EMPLOYER_CABIN,
  683. this.CYCLES,
  684. this.DELAY_CODE_01,
  685. this.DELAY_CODE_02,
  686. this.DELAY_CODE_03,
  687. this.DELAY_CODE_04,
  688. this.DELAY_TIME_01,
  689. this.DELAY_TIME_02,
  690. this.DELAY_TIME_03,
  691. this.DELAY_TIME_04,
  692. this.SUBDELAY_CODE_01,
  693. this.SUBDELAY_CODE_02,
  694. this.SUBDELAY_CODE_03,
  695. this.SUBDELAY_CODE_04,
  696. this.PAX_BOOKED_C,
  697. this.PAX_BOOKED_Y,
  698. this.PAX_BOOKED_TRS_C,
  699. this.PAX_BOOKED_TRS_Y,
  700. this.PAD_BOOKED_C,
  701. this.PAD_BOOKED_Y,
  702. this.OFFBLOCK_DT_A,
  703. this.AIRBORNE_DT_A,
  704. this.LANDING_DT_A,
  705. this.ONBLOCK_DT_A,
  706. this.OFFBLOCK_DT_F,
  707. this.AIRBORNE_DT_F,
  708. this.LANDING_DT_F,
  709. this.ONBLOCK_DT_F,
  710. this.OFFBLOCK_DT_M,
  711. this.AIRBORNE_DT_M,
  712. this.LANDING_DT_M,
  713. this.ONBLOCK_DT_M,
  714. this.EET,
  715. });
  716. Acleg copyWith({
  717. String? LEG_NO,
  718. String? FN_CARRIER,
  719. String? FN_NUMBER,
  720. String? FN_SUFFIX,
  721. String? DAY_OF_ORIGIN,
  722. String? AC_OWNER,
  723. String? AC_SUBTYPE,
  724. String? AC_VERSION,
  725. String? AC_REGISTRATION,
  726. String? DEP_AP_ACTUAL,
  727. String? DEP_AP_SCHED,
  728. String? DEP_DT_EST,
  729. String? DEP_SCHED_DT,
  730. String? ARR_AP_ACTUAL,
  731. String? ARR_AP_SCHED,
  732. String? ARR_DT_EST,
  733. String? ARR_SCHED_DT,
  734. String? SLOT_TIME_ACTUAL,
  735. String? LEG_TYPE,
  736. String? STATUS,
  737. String? EMPLOYER_COCKPIT,
  738. String? EMPLOYER_CABIN,
  739. String? CYCLES,
  740. String? DELAY_CODE_01,
  741. String? DELAY_CODE_02,
  742. String? DELAY_CODE_03,
  743. String? DELAY_CODE_04,
  744. String? DELAY_TIME_01,
  745. String? DELAY_TIME_02,
  746. String? DELAY_TIME_03,
  747. String? DELAY_TIME_04,
  748. String? SUBDELAY_CODE_01,
  749. String? SUBDELAY_CODE_02,
  750. String? SUBDELAY_CODE_03,
  751. String? SUBDELAY_CODE_04,
  752. String? PAX_BOOKED_C,
  753. String? PAX_BOOKED_Y,
  754. String? PAX_BOOKED_TRS_C,
  755. String? PAX_BOOKED_TRS_Y,
  756. String? PAD_BOOKED_C,
  757. String? PAD_BOOKED_Y,
  758. String? OFFBLOCK_DT_A,
  759. String? AIRBORNE_DT_A,
  760. String? LANDING_DT_A,
  761. String? ONBLOCK_DT_A,
  762. String? OFFBLOCK_DT_F,
  763. String? AIRBORNE_DT_F,
  764. String? LANDING_DT_F,
  765. String? ONBLOCK_DT_F,
  766. String? OFFBLOCK_DT_M,
  767. String? AIRBORNE_DT_M,
  768. String? LANDING_DT_M,
  769. String? ONBLOCK_DT_M,
  770. String? EET,
  771. }) {
  772. return Acleg(
  773. LEG_NO: LEG_NO ?? this.LEG_NO,
  774. FN_CARRIER: FN_CARRIER ?? this.FN_CARRIER,
  775. FN_NUMBER: FN_NUMBER ?? this.FN_NUMBER,
  776. FN_SUFFIX: FN_SUFFIX ?? this.FN_SUFFIX,
  777. DAY_OF_ORIGIN: DAY_OF_ORIGIN ?? this.DAY_OF_ORIGIN,
  778. AC_OWNER: AC_OWNER ?? this.AC_OWNER,
  779. AC_SUBTYPE: AC_SUBTYPE ?? this.AC_SUBTYPE,
  780. AC_VERSION: AC_VERSION ?? this.AC_VERSION,
  781. AC_REGISTRATION: AC_REGISTRATION ?? this.AC_REGISTRATION,
  782. DEP_AP_ACTUAL: DEP_AP_ACTUAL ?? this.DEP_AP_ACTUAL,
  783. DEP_AP_SCHED: DEP_AP_SCHED ?? this.DEP_AP_SCHED,
  784. DEP_DT_EST: DEP_DT_EST ?? this.DEP_DT_EST,
  785. DEP_SCHED_DT: DEP_SCHED_DT ?? this.DEP_SCHED_DT,
  786. ARR_AP_ACTUAL: ARR_AP_ACTUAL ?? this.ARR_AP_ACTUAL,
  787. ARR_AP_SCHED: ARR_AP_SCHED ?? this.ARR_AP_SCHED,
  788. ARR_DT_EST: ARR_DT_EST ?? this.ARR_DT_EST,
  789. ARR_SCHED_DT: ARR_SCHED_DT ?? this.ARR_SCHED_DT,
  790. SLOT_TIME_ACTUAL: SLOT_TIME_ACTUAL ?? this.SLOT_TIME_ACTUAL,
  791. LEG_TYPE: LEG_TYPE ?? this.LEG_TYPE,
  792. STATUS: STATUS ?? this.STATUS,
  793. EMPLOYER_COCKPIT: EMPLOYER_COCKPIT ?? this.EMPLOYER_COCKPIT,
  794. EMPLOYER_CABIN: EMPLOYER_CABIN ?? this.EMPLOYER_CABIN,
  795. CYCLES: CYCLES ?? this.CYCLES,
  796. DELAY_CODE_01: DELAY_CODE_01 ?? this.DELAY_CODE_01,
  797. DELAY_CODE_02: DELAY_CODE_02 ?? this.DELAY_CODE_02,
  798. DELAY_CODE_03: DELAY_CODE_03 ?? this.DELAY_CODE_03,
  799. DELAY_CODE_04: DELAY_CODE_04 ?? this.DELAY_CODE_04,
  800. DELAY_TIME_01: DELAY_TIME_01 ?? this.DELAY_TIME_01,
  801. DELAY_TIME_02: DELAY_TIME_02 ?? this.DELAY_TIME_02,
  802. DELAY_TIME_03: DELAY_TIME_03 ?? this.DELAY_TIME_03,
  803. DELAY_TIME_04: DELAY_TIME_04 ?? this.DELAY_TIME_04,
  804. SUBDELAY_CODE_01: SUBDELAY_CODE_01 ?? this.SUBDELAY_CODE_01,
  805. SUBDELAY_CODE_02: SUBDELAY_CODE_02 ?? this.SUBDELAY_CODE_02,
  806. SUBDELAY_CODE_03: SUBDELAY_CODE_03 ?? this.SUBDELAY_CODE_03,
  807. SUBDELAY_CODE_04: SUBDELAY_CODE_04 ?? this.SUBDELAY_CODE_04,
  808. PAX_BOOKED_C: PAX_BOOKED_C ?? this.PAX_BOOKED_C,
  809. PAX_BOOKED_Y: PAX_BOOKED_Y ?? this.PAX_BOOKED_Y,
  810. PAX_BOOKED_TRS_C: PAX_BOOKED_TRS_C ?? this.PAX_BOOKED_TRS_C,
  811. PAX_BOOKED_TRS_Y: PAX_BOOKED_TRS_Y ?? this.PAX_BOOKED_TRS_Y,
  812. PAD_BOOKED_C: PAD_BOOKED_C ?? this.PAD_BOOKED_C,
  813. PAD_BOOKED_Y: PAD_BOOKED_Y ?? this.PAD_BOOKED_Y,
  814. OFFBLOCK_DT_A: OFFBLOCK_DT_A ?? this.OFFBLOCK_DT_A,
  815. AIRBORNE_DT_A: AIRBORNE_DT_A ?? this.AIRBORNE_DT_A,
  816. LANDING_DT_A: LANDING_DT_A ?? this.LANDING_DT_A,
  817. ONBLOCK_DT_A: ONBLOCK_DT_A ?? this.ONBLOCK_DT_A,
  818. OFFBLOCK_DT_F: OFFBLOCK_DT_F ?? this.OFFBLOCK_DT_F,
  819. AIRBORNE_DT_F: AIRBORNE_DT_F ?? this.AIRBORNE_DT_F,
  820. LANDING_DT_F: LANDING_DT_F ?? this.LANDING_DT_F,
  821. ONBLOCK_DT_F: ONBLOCK_DT_F ?? this.ONBLOCK_DT_F,
  822. OFFBLOCK_DT_M: OFFBLOCK_DT_M ?? this.OFFBLOCK_DT_M,
  823. AIRBORNE_DT_M: AIRBORNE_DT_M ?? this.AIRBORNE_DT_M,
  824. LANDING_DT_M: LANDING_DT_M ?? this.LANDING_DT_M,
  825. ONBLOCK_DT_M: ONBLOCK_DT_M ?? this.ONBLOCK_DT_M,
  826. EET: EET ?? this.EET,
  827. );
  828. }
  829. Map<String, dynamic> toMap() {
  830. return <String, dynamic>{
  831. 'LEG_NO': LEG_NO,
  832. 'FN_CARRIER': FN_CARRIER,
  833. 'FN_NUMBER': FN_NUMBER,
  834. 'FN_SUFFIX': FN_SUFFIX,
  835. 'DAY_OF_ORIGIN': DAY_OF_ORIGIN,
  836. 'AC_OWNER': AC_OWNER,
  837. 'AC_SUBTYPE': AC_SUBTYPE,
  838. 'AC_VERSION': AC_VERSION,
  839. 'AC_REGISTRATION': AC_REGISTRATION,
  840. 'DEP_AP_ACTUAL': DEP_AP_ACTUAL,
  841. 'DEP_AP_SCHED': DEP_AP_SCHED,
  842. 'DEP_DT_EST': DEP_DT_EST,
  843. 'DEP_SCHED_DT': DEP_SCHED_DT,
  844. 'ARR_AP_ACTUAL': ARR_AP_ACTUAL,
  845. 'ARR_AP_SCHED': ARR_AP_SCHED,
  846. 'ARR_DT_EST': ARR_DT_EST,
  847. 'ARR_SCHED_DT': ARR_SCHED_DT,
  848. 'SLOT_TIME_ACTUAL': SLOT_TIME_ACTUAL,
  849. 'LEG_TYPE': LEG_TYPE,
  850. 'STATUS': STATUS,
  851. 'EMPLOYER_COCKPIT': EMPLOYER_COCKPIT,
  852. 'EMPLOYER_CABIN': EMPLOYER_CABIN,
  853. 'CYCLES': CYCLES,
  854. 'DELAY_CODE_01': DELAY_CODE_01,
  855. 'DELAY_CODE_02': DELAY_CODE_02,
  856. 'DELAY_CODE_03': DELAY_CODE_03,
  857. 'DELAY_CODE_04': DELAY_CODE_04,
  858. 'DELAY_TIME_01': DELAY_TIME_01,
  859. 'DELAY_TIME_02': DELAY_TIME_02,
  860. 'DELAY_TIME_03': DELAY_TIME_03,
  861. 'DELAY_TIME_04': DELAY_TIME_04,
  862. 'SUBDELAY_CODE_01': SUBDELAY_CODE_01,
  863. 'SUBDELAY_CODE_02': SUBDELAY_CODE_02,
  864. 'SUBDELAY_CODE_03': SUBDELAY_CODE_03,
  865. 'SUBDELAY_CODE_04': SUBDELAY_CODE_04,
  866. 'PAX_BOOKED_C': PAX_BOOKED_C,
  867. 'PAX_BOOKED_Y': PAX_BOOKED_Y,
  868. 'PAX_BOOKED_TRS_C': PAX_BOOKED_TRS_C,
  869. 'PAX_BOOKED_TRS_Y': PAX_BOOKED_TRS_Y,
  870. 'PAD_BOOKED_C': PAD_BOOKED_C,
  871. 'PAD_BOOKED_Y': PAD_BOOKED_Y,
  872. 'OFFBLOCK_DT_A': OFFBLOCK_DT_A,
  873. 'AIRBORNE_DT_A': AIRBORNE_DT_A,
  874. 'LANDING_DT_A': LANDING_DT_A,
  875. 'ONBLOCK_DT_A': ONBLOCK_DT_A,
  876. 'OFFBLOCK_DT_F': OFFBLOCK_DT_F,
  877. 'AIRBORNE_DT_F': AIRBORNE_DT_F,
  878. 'LANDING_DT_F': LANDING_DT_F,
  879. 'ONBLOCK_DT_F': ONBLOCK_DT_F,
  880. 'OFFBLOCK_DT_M': OFFBLOCK_DT_M,
  881. 'AIRBORNE_DT_M': AIRBORNE_DT_M,
  882. 'LANDING_DT_M': LANDING_DT_M,
  883. 'ONBLOCK_DT_M': ONBLOCK_DT_M,
  884. 'EET': EET,
  885. };
  886. }
  887. factory Acleg.fromList(List datalist) {
  888. //print(datalist);
  889. if (datalist.length >= 54) {
  890. return Acleg(
  891. LEG_NO: datalist[0],
  892. FN_CARRIER: datalist[1],
  893. FN_NUMBER: datalist[2],
  894. FN_SUFFIX: datalist[3],
  895. DAY_OF_ORIGIN: datalist[4],
  896. AC_OWNER: datalist[5],
  897. AC_SUBTYPE: datalist[6],
  898. AC_VERSION: datalist[7],
  899. AC_REGISTRATION: datalist[8],
  900. DEP_AP_ACTUAL: datalist[9],
  901. DEP_AP_SCHED: datalist[10],
  902. DEP_DT_EST: datalist[11],
  903. DEP_SCHED_DT: datalist[12],
  904. ARR_AP_ACTUAL: datalist[13],
  905. ARR_AP_SCHED: datalist[14],
  906. ARR_DT_EST: datalist[15],
  907. ARR_SCHED_DT: datalist[16],
  908. SLOT_TIME_ACTUAL: datalist[17],
  909. LEG_TYPE: datalist[18],
  910. STATUS: datalist[19],
  911. EMPLOYER_COCKPIT: datalist[20],
  912. EMPLOYER_CABIN: datalist[21],
  913. CYCLES: datalist[22],
  914. DELAY_CODE_01: datalist[23],
  915. DELAY_CODE_02: datalist[24],
  916. DELAY_CODE_03: datalist[25],
  917. DELAY_CODE_04: datalist[26],
  918. DELAY_TIME_01: datalist[27],
  919. DELAY_TIME_02: datalist[28],
  920. DELAY_TIME_03: datalist[29],
  921. DELAY_TIME_04: datalist[30],
  922. SUBDELAY_CODE_01: datalist[31],
  923. SUBDELAY_CODE_02: datalist[32],
  924. SUBDELAY_CODE_03: datalist[33],
  925. SUBDELAY_CODE_04: datalist[34],
  926. PAX_BOOKED_C: datalist[35],
  927. PAX_BOOKED_Y: datalist[36],
  928. PAX_BOOKED_TRS_C: datalist[37],
  929. PAX_BOOKED_TRS_Y: datalist[38],
  930. PAD_BOOKED_C: datalist[39],
  931. PAD_BOOKED_Y: datalist[40],
  932. OFFBLOCK_DT_A: datalist[41],
  933. AIRBORNE_DT_A: datalist[42],
  934. LANDING_DT_A: datalist[43],
  935. ONBLOCK_DT_A: datalist[44],
  936. OFFBLOCK_DT_F: datalist[45],
  937. AIRBORNE_DT_F: datalist[46],
  938. LANDING_DT_F: datalist[47],
  939. ONBLOCK_DT_F: datalist[48],
  940. OFFBLOCK_DT_M: datalist[49],
  941. AIRBORNE_DT_M: datalist[50],
  942. LANDING_DT_M: datalist[51],
  943. ONBLOCK_DT_M: datalist[52],
  944. EET: datalist[53]);
  945. } else {
  946. return Acleg();
  947. }
  948. }
  949. factory Acleg.fromMap(Map<String, dynamic> map) {
  950. return Acleg(
  951. LEG_NO: map['LEG_NO'] != null ? map['LEG_NO'] as String : null,
  952. FN_CARRIER:
  953. map['FN_CARRIER'] != null ? map['FN_CARRIER'] as String : null,
  954. FN_NUMBER: map['FN_NUMBER'] != null ? map['FN_NUMBER'] as String : null,
  955. FN_SUFFIX: map['FN_SUFFIX'] != null ? map['FN_SUFFIX'] as String : null,
  956. DAY_OF_ORIGIN:
  957. map['DAY_OF_ORIGIN'] != null ? map['DAY_OF_ORIGIN'] as String : null,
  958. AC_OWNER: map['AC_OWNER'] != null ? map['AC_OWNER'] as String : null,
  959. AC_SUBTYPE:
  960. map['AC_SUBTYPE'] != null ? map['AC_SUBTYPE'] as String : null,
  961. AC_VERSION:
  962. map['AC_VERSION'] != null ? map['AC_VERSION'] as String : null,
  963. AC_REGISTRATION: map['AC_REGISTRATION'] != null
  964. ? map['AC_REGISTRATION'] as String
  965. : null,
  966. DEP_AP_ACTUAL:
  967. map['DEP_AP_ACTUAL'] != null ? map['DEP_AP_ACTUAL'] as String : null,
  968. DEP_AP_SCHED:
  969. map['DEP_AP_SCHED'] != null ? map['DEP_AP_SCHED'] as String : null,
  970. DEP_DT_EST:
  971. map['DEP_DT_EST'] != null ? map['DEP_DT_EST'] as String : null,
  972. DEP_SCHED_DT:
  973. map['DEP_SCHED_DT'] != null ? map['DEP_SCHED_DT'] as String : null,
  974. ARR_AP_ACTUAL:
  975. map['ARR_AP_ACTUAL'] != null ? map['ARR_AP_ACTUAL'] as String : null,
  976. ARR_AP_SCHED:
  977. map['ARR_AP_SCHED'] != null ? map['ARR_AP_SCHED'] as String : null,
  978. ARR_DT_EST:
  979. map['ARR_DT_EST'] != null ? map['ARR_DT_EST'] as String : null,
  980. ARR_SCHED_DT:
  981. map['ARR_SCHED_DT'] != null ? map['ARR_SCHED_DT'] as String : null,
  982. SLOT_TIME_ACTUAL: map['SLOT_TIME_ACTUAL'] != null
  983. ? map['SLOT_TIME_ACTUAL'] as String
  984. : null,
  985. LEG_TYPE: map['LEG_TYPE'] != null ? map['LEG_TYPE'] as String : null,
  986. EMPLOYER_COCKPIT: map['EMPLOYER_COCKPIT'] != null
  987. ? map['EMPLOYER_COCKPIT'] as String
  988. : null,
  989. EMPLOYER_CABIN: map['EMPLOYER_CABIN'] != null
  990. ? map['EMPLOYER_CABIN'] as String
  991. : null,
  992. // CYCLES: map['CYCLES'] != null ? map['CYCLES'] as String : null,
  993. DELAY_CODE_01:
  994. map['DELAY_CODE_01'] != null ? map['DELAY_CODE_01'] as String : null,
  995. DELAY_CODE_02:
  996. map['DELAY_CODE_02'] != null ? map['DELAY_CODE_02'] as String : null,
  997. DELAY_CODE_03:
  998. map['DELAY_CODE_03'] != null ? map['DELAY_CODE_03'] as String : null,
  999. DELAY_CODE_04:
  1000. map['DELAY_CODE_04'] != null ? map['DELAY_CODE_04'] as String : null,
  1001. DELAY_TIME_01:
  1002. map['DELAY_TIME_01'] != null ? map['DELAY_TIME_01'] as String : null,
  1003. DELAY_TIME_02:
  1004. map['DELAY_TIME_02'] != null ? map['DELAY_TIME_02'] as String : null,
  1005. DELAY_TIME_03:
  1006. map['DELAY_TIME_03'] != null ? map['DELAY_TIME_03'] as String : null,
  1007. DELAY_TIME_04:
  1008. map['DELAY_TIME_04'] != null ? map['DELAY_TIME_04'] as String : null,
  1009. SUBDELAY_CODE_01: map['SUBDELAY_CODE_01'] != null
  1010. ? map['SUBDELAY_CODE_01'] as String
  1011. : null,
  1012. SUBDELAY_CODE_02: map['SUBDELAY_CODE_02'] != null
  1013. ? map['SUBDELAY_CODE_02'] as String
  1014. : null,
  1015. SUBDELAY_CODE_03: map['SUBDELAY_CODE_03'] != null
  1016. ? map['SUBDELAY_CODE_03'] as String
  1017. : null,
  1018. SUBDELAY_CODE_04: map['SUBDELAY_CODE_04'] != null
  1019. ? map['SUBDELAY_CODE_04'] as String
  1020. : null,
  1021. PAX_BOOKED_C:
  1022. map['PAX_BOOKED_C'] != null ? map['PAX_BOOKED_C'] as String : null,
  1023. PAX_BOOKED_Y:
  1024. map['PAX_BOOKED_Y'] != null ? map['PAX_BOOKED_Y'] as String : null,
  1025. PAX_BOOKED_TRS_C: map['PAX_BOOKED_TRS_C'] != null
  1026. ? map['PAX_BOOKED_TRS_C'] as String
  1027. : null,
  1028. PAX_BOOKED_TRS_Y: map['PAX_BOOKED_TRS_Y'] != null
  1029. ? map['PAX_BOOKED_TRS_Y'] as String
  1030. : null,
  1031. PAD_BOOKED_C:
  1032. map['PAD_BOOKED_C'] != null ? map['PAD_BOOKED_C'] as String : null,
  1033. PAD_BOOKED_Y:
  1034. map['PAD_BOOKED_Y'] != null ? map['PAD_BOOKED_Y'] as String : null,
  1035. OFFBLOCK_DT_A:
  1036. map['OFFBLOCK_DT_A'] != null ? map['OFFBLOCK_DT_A'] as String : null,
  1037. AIRBORNE_DT_A:
  1038. map['AIRBORNE_DT_A'] != null ? map['AIRBORNE_DT_A'] as String : null,
  1039. LANDING_DT_A:
  1040. map['LANDING_DT_A'] != null ? map['LANDING_DT_A'] as String : null,
  1041. ONBLOCK_DT_A:
  1042. map['ONBLOCK_DT_A'] != null ? map['ONBLOCK_DT_A'] as String : null,
  1043. OFFBLOCK_DT_F:
  1044. map['OFFBLOCK_DT_F'] != null ? map['OFFBLOCK_DT_F'] as String : null,
  1045. AIRBORNE_DT_F:
  1046. map['AIRBORNE_DT_F'] != null ? map['AIRBORNE_DT_F'] as String : null,
  1047. LANDING_DT_F:
  1048. map['LANDING_DT_F'] != null ? map['LANDING_DT_F'] as String : null,
  1049. ONBLOCK_DT_F:
  1050. map['ONBLOCK_DT_F'] != null ? map['ONBLOCK_DT_F'] as String : null,
  1051. OFFBLOCK_DT_M:
  1052. map['OFFBLOCK_DT_M'] != null ? map['OFFBLOCK_DT_M'] as String : null,
  1053. AIRBORNE_DT_M:
  1054. map['AIRBORNE_DT_M'] != null ? map['AIRBORNE_DT_M'] as String : null,
  1055. LANDING_DT_M:
  1056. map['LANDING_DT_M'] != null ? map['LANDING_DT_M'] as String : null,
  1057. ONBLOCK_DT_M:
  1058. map['ONBLOCK_DT_M'] != null ? map['ONBLOCK_DT_M'] as String : null,
  1059. EET: map['EET'] != null ? map['EET'] as String : null,
  1060. );
  1061. }
  1062. String toJson() => json.encode(toMap());
  1063. factory Acleg.fromJson(String source) =>
  1064. Acleg.fromMap(json.decode(source) as Map<String, dynamic>);
  1065. @override
  1066. String toString() {
  1067. return 'Acleg(LEG_NO: $LEG_NO, FN_CARRIER: $FN_CARRIER, FN_NUMBER: $FN_NUMBER, FN_SUFFIX: $FN_SUFFIX, DAY_OF_ORIGIN: $DAY_OF_ORIGIN, AC_OWNER: $AC_OWNER, AC_SUBTYPE: $AC_SUBTYPE, AC_VERSION: $AC_VERSION, AC_REGISTRATION: $AC_REGISTRATION, DEP_AP_ACTUAL: $DEP_AP_ACTUAL, DEP_AP_SCHED: $DEP_AP_SCHED, DEP_DT_EST: $DEP_DT_EST, DEP_SCHED_DT: $DEP_SCHED_DT, ARR_AP_ACTUAL: $ARR_AP_ACTUAL, ARR_AP_SCHED: $ARR_AP_SCHED, ARR_DT_EST: $ARR_DT_EST, ARR_SCHED_DT: $ARR_SCHED_DT, SLOT_TIME_ACTUAL: $SLOT_TIME_ACTUAL, LEG_TYPE: $LEG_TYPE, EMPLOYER_COCKPIT: $EMPLOYER_COCKPIT, EMPLOYER_CABIN: $EMPLOYER_CABIN, CYCLES: $CYCLES, DELAY_CODE_01: $DELAY_CODE_01, DELAY_CODE_02: $DELAY_CODE_02, DELAY_CODE_03: $DELAY_CODE_03, DELAY_CODE_04: $DELAY_CODE_04, DELAY_TIME_01: $DELAY_TIME_01, DELAY_TIME_02: $DELAY_TIME_02, DELAY_TIME_03: $DELAY_TIME_03, DELAY_TIME_04: $DELAY_TIME_04, SUBDELAY_CODE_01: $SUBDELAY_CODE_01, SUBDELAY_CODE_02: $SUBDELAY_CODE_02, SUBDELAY_CODE_03: $SUBDELAY_CODE_03, SUBDELAY_CODE_04: $SUBDELAY_CODE_04, PAX_BOOKED_C: $PAX_BOOKED_C, PAX_BOOKED_Y: $PAX_BOOKED_Y, PAX_BOOKED_TRS_C: $PAX_BOOKED_TRS_C, PAX_BOOKED_TRS_Y: $PAX_BOOKED_TRS_Y, PAD_BOOKED_C: $PAD_BOOKED_C, PAD_BOOKED_Y: $PAD_BOOKED_Y, OFFBLOCK_DT_A: $OFFBLOCK_DT_A, AIRBORNE_DT_A: $AIRBORNE_DT_A, LANDING_DT_A: $LANDING_DT_A, ONBLOCK_DT_A: $ONBLOCK_DT_A, OFFBLOCK_DT_F: $OFFBLOCK_DT_F, AIRBORNE_DT_F: $AIRBORNE_DT_F, LANDING_DT_F: $LANDING_DT_F, ONBLOCK_DT_F: $ONBLOCK_DT_F, OFFBLOCK_DT_M: $OFFBLOCK_DT_M, AIRBORNE_DT_M: $AIRBORNE_DT_M, LANDING_DT_M: $LANDING_DT_M, ONBLOCK_DT_M: $ONBLOCK_DT_M, EET: $EET)';
  1068. }
  1069. @override
  1070. bool operator ==(covariant Acleg other) {
  1071. if (identical(this, other)) return true;
  1072. return other.LEG_NO == LEG_NO &&
  1073. other.FN_CARRIER == FN_CARRIER &&
  1074. other.FN_NUMBER == FN_NUMBER &&
  1075. other.FN_SUFFIX == FN_SUFFIX &&
  1076. other.DAY_OF_ORIGIN == DAY_OF_ORIGIN &&
  1077. other.AC_OWNER == AC_OWNER &&
  1078. other.AC_SUBTYPE == AC_SUBTYPE &&
  1079. other.AC_VERSION == AC_VERSION &&
  1080. other.AC_REGISTRATION == AC_REGISTRATION &&
  1081. other.DEP_AP_ACTUAL == DEP_AP_ACTUAL &&
  1082. other.DEP_AP_SCHED == DEP_AP_SCHED &&
  1083. other.DEP_DT_EST == DEP_DT_EST &&
  1084. other.DEP_SCHED_DT == DEP_SCHED_DT &&
  1085. other.ARR_AP_ACTUAL == ARR_AP_ACTUAL &&
  1086. other.ARR_AP_SCHED == ARR_AP_SCHED &&
  1087. other.ARR_DT_EST == ARR_DT_EST &&
  1088. other.ARR_SCHED_DT == ARR_SCHED_DT &&
  1089. other.SLOT_TIME_ACTUAL == SLOT_TIME_ACTUAL &&
  1090. other.LEG_TYPE == LEG_TYPE &&
  1091. other.EMPLOYER_COCKPIT == EMPLOYER_COCKPIT &&
  1092. other.EMPLOYER_CABIN == EMPLOYER_CABIN &&
  1093. other.CYCLES == CYCLES &&
  1094. other.DELAY_CODE_01 == DELAY_CODE_01 &&
  1095. other.DELAY_CODE_02 == DELAY_CODE_02 &&
  1096. other.DELAY_CODE_03 == DELAY_CODE_03 &&
  1097. other.DELAY_CODE_04 == DELAY_CODE_04 &&
  1098. other.DELAY_TIME_01 == DELAY_TIME_01 &&
  1099. other.DELAY_TIME_02 == DELAY_TIME_02 &&
  1100. other.DELAY_TIME_03 == DELAY_TIME_03 &&
  1101. other.DELAY_TIME_04 == DELAY_TIME_04 &&
  1102. other.SUBDELAY_CODE_01 == SUBDELAY_CODE_01 &&
  1103. other.SUBDELAY_CODE_02 == SUBDELAY_CODE_02 &&
  1104. other.SUBDELAY_CODE_03 == SUBDELAY_CODE_03 &&
  1105. other.SUBDELAY_CODE_04 == SUBDELAY_CODE_04 &&
  1106. other.PAX_BOOKED_C == PAX_BOOKED_C &&
  1107. other.PAX_BOOKED_Y == PAX_BOOKED_Y &&
  1108. other.PAX_BOOKED_TRS_C == PAX_BOOKED_TRS_C &&
  1109. other.PAX_BOOKED_TRS_Y == PAX_BOOKED_TRS_Y &&
  1110. other.PAD_BOOKED_C == PAD_BOOKED_C &&
  1111. other.PAD_BOOKED_Y == PAD_BOOKED_Y &&
  1112. other.OFFBLOCK_DT_A == OFFBLOCK_DT_A &&
  1113. other.AIRBORNE_DT_A == AIRBORNE_DT_A &&
  1114. other.LANDING_DT_A == LANDING_DT_A &&
  1115. other.ONBLOCK_DT_A == ONBLOCK_DT_A &&
  1116. other.OFFBLOCK_DT_F == OFFBLOCK_DT_F &&
  1117. other.AIRBORNE_DT_F == AIRBORNE_DT_F &&
  1118. other.LANDING_DT_F == LANDING_DT_F &&
  1119. other.ONBLOCK_DT_F == ONBLOCK_DT_F &&
  1120. other.OFFBLOCK_DT_M == OFFBLOCK_DT_M &&
  1121. other.AIRBORNE_DT_M == AIRBORNE_DT_M &&
  1122. other.LANDING_DT_M == LANDING_DT_M &&
  1123. other.ONBLOCK_DT_M == ONBLOCK_DT_M &&
  1124. other.EET == EET;
  1125. }
  1126. @override
  1127. int get hashCode {
  1128. return LEG_NO.hashCode ^
  1129. FN_CARRIER.hashCode ^
  1130. FN_NUMBER.hashCode ^
  1131. FN_SUFFIX.hashCode ^
  1132. DAY_OF_ORIGIN.hashCode ^
  1133. AC_OWNER.hashCode ^
  1134. AC_SUBTYPE.hashCode ^
  1135. AC_VERSION.hashCode ^
  1136. AC_REGISTRATION.hashCode ^
  1137. DEP_AP_ACTUAL.hashCode ^
  1138. DEP_AP_SCHED.hashCode ^
  1139. DEP_DT_EST.hashCode ^
  1140. DEP_SCHED_DT.hashCode ^
  1141. ARR_AP_ACTUAL.hashCode ^
  1142. ARR_AP_SCHED.hashCode ^
  1143. ARR_DT_EST.hashCode ^
  1144. ARR_SCHED_DT.hashCode ^
  1145. SLOT_TIME_ACTUAL.hashCode ^
  1146. LEG_TYPE.hashCode ^
  1147. EMPLOYER_COCKPIT.hashCode ^
  1148. EMPLOYER_CABIN.hashCode ^
  1149. CYCLES.hashCode ^
  1150. DELAY_CODE_01.hashCode ^
  1151. DELAY_CODE_02.hashCode ^
  1152. DELAY_CODE_03.hashCode ^
  1153. DELAY_CODE_04.hashCode ^
  1154. DELAY_TIME_01.hashCode ^
  1155. DELAY_TIME_02.hashCode ^
  1156. DELAY_TIME_03.hashCode ^
  1157. DELAY_TIME_04.hashCode ^
  1158. SUBDELAY_CODE_01.hashCode ^
  1159. SUBDELAY_CODE_02.hashCode ^
  1160. SUBDELAY_CODE_03.hashCode ^
  1161. SUBDELAY_CODE_04.hashCode ^
  1162. PAX_BOOKED_C.hashCode ^
  1163. PAX_BOOKED_Y.hashCode ^
  1164. PAX_BOOKED_TRS_C.hashCode ^
  1165. PAX_BOOKED_TRS_Y.hashCode ^
  1166. PAD_BOOKED_C.hashCode ^
  1167. PAD_BOOKED_Y.hashCode ^
  1168. OFFBLOCK_DT_A.hashCode ^
  1169. AIRBORNE_DT_A.hashCode ^
  1170. LANDING_DT_A.hashCode ^
  1171. ONBLOCK_DT_A.hashCode ^
  1172. OFFBLOCK_DT_F.hashCode ^
  1173. AIRBORNE_DT_F.hashCode ^
  1174. LANDING_DT_F.hashCode ^
  1175. ONBLOCK_DT_F.hashCode ^
  1176. OFFBLOCK_DT_M.hashCode ^
  1177. AIRBORNE_DT_M.hashCode ^
  1178. LANDING_DT_M.hashCode ^
  1179. ONBLOCK_DT_M.hashCode ^
  1180. EET.hashCode;
  1181. }
  1182. }
  1183. extension StringExtensions on String {
  1184. String capitalize() {
  1185. if (isEmpty) {
  1186. return this;
  1187. } else {
  1188. return "${this[0].toUpperCase()}${substring(1).toLowerCase()}";
  1189. }
  1190. }
  1191. String capitalizeword() {
  1192. return split(' ').map((word) => word.capitalize()).join(' ');
  1193. }
  1194. Jiffy? parseddmmyyyyhhmm() => length >= 15
  1195. ? Jiffy.parse(
  1196. "${substring(6, 10)}-${substring(3, 5)}-${substring(0, 2)} ${substring(11, 13)}:${substring(13, 15)}",
  1197. pattern: 'yyyy-MM-dd HH:mm',
  1198. isUtc: true)
  1199. : null;
  1200. Jiffy? parseyyyymmddhhmm() => length >= 16
  1201. ? Jiffy.parse(this,
  1202. pattern: 'yyyy-MM-dd HH:mm:ss',
  1203. // "${substring(6, 10)}-${substring(3, 5)}-${substring(0, 2)} ${substring(11, 13)}${substring(13, 16)}",
  1204. // pattern: 'yyyy-MM-dd HH:mm',
  1205. isUtc: true)
  1206. : null;
  1207. }
  1208. class FilesAsData {
  1209. String? filename;
  1210. String? updatedAt;
  1211. String data;
  1212. FilesAsData({
  1213. this.filename,
  1214. this.updatedAt,
  1215. required this.data,
  1216. });
  1217. }
  1218. const maxItemsToSelect = 200;
  1219. const maxItemsToInsert = 500;
  1220. const maxItemsToRemove = 500;
  1221. processCsvData(File tempfile, SupabaseClient supabase) async {
  1222. List<FilesAsData> csvData = [];
  1223. final filename = tempfile.path.split('/').last;
  1224. // Check if file is a zip archive
  1225. if (filename.toLowerCase().endsWith('.zip')) {
  1226. Archive archive = ZipDecoder().decodeBytes(await tempfile.readAsBytes());
  1227. for (final file in archive) {
  1228. if (!file.isFile) continue;
  1229. csvData.add(FilesAsData(
  1230. filename: file.name, data: utf8.decode(file.content as List<int>)));
  1231. }
  1232. archive.clearSync();
  1233. } else {
  1234. // For non-zip files, store in extracted folder
  1235. csvData.add(FilesAsData(
  1236. filename: filename, data: utf8.decode(await tempfile.readAsBytes())));
  1237. }
  1238. for (final FilesAsData data in csvData) {
  1239. print(" processing ${data.filename}");
  1240. //inserting data
  1241. if (tables.keys.contains(data.filename)) {
  1242. List<Map<String, String?>> mapsToInsert =
  1243. createListOfMaps(headers[data.filename] ?? [], csv2list(data.data));
  1244. final completeMapsToInsert = mapsToInsert;
  1245. final scopeName = scopes[data.filename!]!;
  1246. final scopeInNew = mapsToInsert
  1247. .fold(<String>{}, (t, e) => t..add(e[scopeName] ?? "")).toList();
  1248. // print("Loading old data scope: ${scopeInNew.length}");
  1249. List<Map<String, dynamic>> oldIds = [];
  1250. List<Map<String, dynamic>> oldComparable = [];
  1251. for (var e in splitList(scopeInNew, headerToNb(scopeInNew))) {
  1252. final res = await supabase
  1253. .from(tables[data.filename]!)
  1254. .select()
  1255. .inFilter(scopeName, e)
  1256. .limit(100000);
  1257. oldIds.addAll(res.map((e) => filterMapByKeys(e, ["id"])).toList());
  1258. oldComparable.addAll(res
  1259. .map((e) => filterMapByKeys(e, headers[data.filename] ?? []))
  1260. .toList());
  1261. // print("Loaded old data scope: ${e.length}");
  1262. }
  1263. // Replace with your actual table name
  1264. List<int> indexToRemove = [];
  1265. List<int> indexToMaintain = [];
  1266. // print("Deleting old data scope: ${mapsToInsert.length}");
  1267. final keys2check = idToRemove[data.filename]!;
  1268. final mawjoudin = oldComparable.fold(<Map<String, dynamic>>[], (t, e) {
  1269. t.add(extractMapWithKeys(e, keys2check));
  1270. return t;
  1271. });
  1272. for (int i = 0; i < oldComparable.length; i++) {
  1273. final item = oldComparable[i];
  1274. final index = findIndex(mapsToInsert, item);
  1275. // final mawjood =
  1276. // mawjoudin.contains(extractMapWithKeys(item, keys2check));
  1277. final mawjood = mawjoudin
  1278. .firstWhere(
  1279. (e) => mapEquals(extractMapWithKeys(item, keys2check), e),
  1280. orElse: () => {})
  1281. .keys
  1282. .isNotEmpty;
  1283. if (index > -1) {
  1284. indexToMaintain.add(i);
  1285. mapsToInsert.removeAt(index);
  1286. } else if (mawjood) {
  1287. indexToRemove.add(i);
  1288. } else {
  1289. print("saved item: $item");
  1290. }
  1291. }
  1292. //removing index to remove with id
  1293. for (var e in splitList(
  1294. indexToRemove.map((e) => oldIds[e]['id']).toList(),
  1295. headerToNb(indexToRemove.map((e) => oldIds[e]['id']).toList()))) {
  1296. await supabase
  1297. .from(tables[data.filename]!) // Replace with your actual table name
  1298. .delete()
  1299. .inFilter('id', e);
  1300. }
  1301. // print("Deleted old data scope: ${e.length}");
  1302. //insering new data
  1303. await supabase
  1304. .from(tables[data.filename]!) // Replace with your actual table name
  1305. .insert(mapsToInsert);
  1306. print(
  1307. " insert:${mapsToInsert.length} remove:${indexToRemove.length} maintain:${indexToMaintain.length}");
  1308. } else {
  1309. print(" filename: ${data.filename} unknown, not inserted.");
  1310. }
  1311. }
  1312. }
  1313. bool mapEquals(Map<String, dynamic> map1, Map<String, dynamic> map2) {
  1314. //if (map1.length != map2.length) return false;
  1315. for (var key in map1.keys) {
  1316. if (map1[key] != map2[key]) return false;
  1317. }
  1318. return true;
  1319. }
  1320. int findIndex(List<dynamic> list, dynamic element) {
  1321. for (int i = 0; i < list.length; i++) {
  1322. if (mapEquals(list[i], element)) {
  1323. return i;
  1324. }
  1325. }
  1326. return -1; // Return -1 if the element is not found
  1327. }
  1328. Map<String, dynamic> filterMapByKeys(
  1329. Map<String, dynamic> originalMap, List<String> keysToInclude) {
  1330. // Create a new map to hold the filtered results
  1331. Map<String, dynamic> filteredMap = {};
  1332. // Iterate through the list of keys to include
  1333. for (String key in keysToInclude) {
  1334. // Check if the key exists in the original map
  1335. if (originalMap.containsKey(key)) {
  1336. filteredMap[key] = originalMap[key]; // Add to the new map
  1337. }
  1338. }
  1339. return filteredMap;
  1340. }
  1341. List<List<T>> splitList<T>(List<T> originalList, int maxSize) {
  1342. List<List<T>> sublists = [];
  1343. for (int i = 0; i < originalList.length; i += maxSize) {
  1344. // Create a sublist for the current chunk
  1345. List<T> sublist = originalList.sublist(
  1346. i,
  1347. (i + maxSize > originalList.length) ? originalList.length : i + maxSize,
  1348. );
  1349. sublists.add(sublist);
  1350. }
  1351. return sublists;
  1352. }
  1353. int headerToNb(List list) {
  1354. //header max of 16k
  1355. final maxheader = 4 * 1024 * 8;
  1356. if (list.isEmpty) {
  1357. return list.length;
  1358. }
  1359. final length1 = (list.toString().length / list.length).ceil() * 8;
  1360. final lengthurl = 200 * 8;
  1361. final res = ((maxheader - lengthurl) / length1).floor();
  1362. //print("header2nb: $res");
  1363. return res;
  1364. }
  1365. Map<String, dynamic> findDifferences(
  1366. Map<String, dynamic> map1, Map<String, dynamic> map2) {
  1367. Map<String, dynamic> differences = {};
  1368. // Iterate through keys in map2
  1369. for (var key in map2.keys) {
  1370. // Check if key exists in map1
  1371. if (!map1.containsKey(key) || map1[key] != map2[key]) {
  1372. // Add to differences if it's different or doesn't exist in map1
  1373. differences[key] = map2[key];
  1374. }
  1375. }
  1376. return differences;
  1377. }
  1378. Map<String, dynamic> findSimilarities(
  1379. Map<String, dynamic> map1, Map<String, dynamic> map2) {
  1380. Map<String, dynamic> similarities = {};
  1381. // Iterate through keys in map1
  1382. for (var key in map1.keys) {
  1383. // Check if key exists in map2 and has the same value as map1
  1384. if (map2.containsKey(key) && map1[key] == map2[key]) {
  1385. // Add to similarities if it's the same in both maps
  1386. similarities[key] = map1[key];
  1387. }
  1388. }
  1389. return similarities;
  1390. }
  1391. bool containsAll(List<String> sourceList, List<String> targetList) {
  1392. for (var item in sourceList) {
  1393. if (!targetList.contains(item)) {
  1394. return false;
  1395. }
  1396. }
  1397. return true;
  1398. }
  1399. Map<K, V> extractMapWithKeys<K, V>(Map<K, V> originalMap, List<K> keys) {
  1400. Map<K, V> extractedMap = {};
  1401. for (K key in keys) {
  1402. if (originalMap.containsKey(key)) {
  1403. extractedMap[key] = originalMap[key]!;
  1404. }
  1405. }
  1406. return extractedMap;
  1407. }