Guest User

Launch.dart

a guest
Nov 27th, 2020
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 27.62 KB | None | 0 0
  1. import 'dart:convert';
  2.  
  3. List<Launch> launchFromJson(String str) =>
  4.     List<Launch>.from(json.decode(str).map((x) => Launch.fromJson(x)));
  5.  
  6. String launchToJson(List<Launch> data) =>
  7.     json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
  8.  
  9. class Launch {
  10.   Launch({
  11.     this.flightNumber,
  12.     this.missionName,
  13.     this.missionId,
  14.     this.upcoming,
  15.     this.launchYear,
  16.     this.launchDateUnix,
  17.     this.launchDateUtc,
  18.     this.launchDateLocal,
  19.     this.isTentative,
  20.     this.tentativeMaxPrecision,
  21.     this.tbd,
  22.     this.launchWindow,
  23.     this.rocket,
  24.     this.ships,
  25.     this.telemetry,
  26.     this.reuse,
  27.     this.launchSite,
  28.     this.launchSuccess,
  29.     this.launchFailureDetails,
  30.     this.links,
  31.     this.details,
  32.     this.staticFireDateUtc,
  33.     this.staticFireDateUnix,
  34.     this.timeline,
  35.     this.crew,
  36.     this.lastDateUpdate,
  37.     this.lastLlLaunchDate,
  38.     this.lastLlUpdate,
  39.     this.lastWikiLaunchDate,
  40.     this.lastWikiRevision,
  41.     this.lastWikiUpdate,
  42.     this.launchDateSource,
  43.   });
  44.  
  45.   int flightNumber;
  46.   String missionName;
  47.   List<String> missionId;
  48.   bool upcoming;
  49.   String launchYear;
  50.   int launchDateUnix;
  51.   DateTime launchDateUtc;
  52.   DateTime launchDateLocal;
  53.   bool isTentative;
  54.   TentativeMaxPrecision tentativeMaxPrecision;
  55.   bool tbd;
  56.   int launchWindow;
  57.   Rocket rocket;
  58.   List<String> ships;
  59.   Telemetry telemetry;
  60.   Reuse reuse;
  61.   LaunchSite launchSite;
  62.   bool launchSuccess;
  63.   LaunchFailureDetails launchFailureDetails;
  64.   Links links;
  65.   String details;
  66.   DateTime staticFireDateUtc;
  67.   int staticFireDateUnix;
  68.   Map<String, int> timeline;
  69.   dynamic crew;
  70.   DateTime lastDateUpdate;
  71.   DateTime lastLlLaunchDate;
  72.   DateTime lastLlUpdate;
  73.   DateTime lastWikiLaunchDate;
  74.   String lastWikiRevision;
  75.   DateTime lastWikiUpdate;
  76.   LaunchDateSource launchDateSource;
  77.  
  78.   factory Launch.fromJson(Map<String, dynamic> json) => Launch(
  79.         flightNumber: json["flight_number"],
  80.         missionName: json["mission_name"],
  81.         missionId: List<String>.from(json["mission_id"].map((x) => x)),
  82.         upcoming: json["upcoming"],
  83.         launchYear: json["launch_year"],
  84.         launchDateUnix: json["launch_date_unix"],
  85.         launchDateUtc: DateTime.parse(json["launch_date_utc"]),
  86.         launchDateLocal: DateTime.parse(json["launch_date_local"]),
  87.         isTentative: json["is_tentative"],
  88.         tentativeMaxPrecision:
  89.             tentativeMaxPrecisionValues.map[json["tentative_max_precision"]],
  90.         tbd: json["tbd"],
  91.         launchWindow:
  92.             json["launch_window"] == null ? null : json["launch_window"],
  93.         rocket: Rocket.fromJson(json["rocket"]),
  94.         ships: List<String>.from(json["ships"].map((x) => x)),
  95.         telemetry: Telemetry.fromJson(json["telemetry"]),
  96.         reuse: Reuse.fromJson(json["reuse"]),
  97.         launchSite: LaunchSite.fromJson(json["launch_site"]),
  98.         launchSuccess:
  99.             json["launch_success"] == null ? null : json["launch_success"],
  100.         launchFailureDetails: json["launch_failure_details"] == null
  101.             ? null
  102.             : LaunchFailureDetails.fromJson(json["launch_failure_details"]),
  103.         links: Links.fromJson(json["links"]),
  104.         details: json["details"] == null ? null : json["details"],
  105.         staticFireDateUtc: json["static_fire_date_utc"] == null
  106.             ? null
  107.             : DateTime.parse(json["static_fire_date_utc"]),
  108.         staticFireDateUnix: json["static_fire_date_unix"] == null
  109.             ? null
  110.             : json["static_fire_date_unix"],
  111.         timeline: json["timeline"] == null
  112.             ? null
  113.             : Map.from(json["timeline"])
  114.                 .map((k, v) => MapEntry<String, int>(k, v == null ? null : v)),
  115.         crew: json["crew"],
  116.         lastDateUpdate: json["last_date_update"] == null
  117.             ? null
  118.             : DateTime.parse(json["last_date_update"]),
  119.         lastLlLaunchDate: json["last_ll_launch_date"] == null
  120.             ? null
  121.             : DateTime.parse(json["last_ll_launch_date"]),
  122.         lastLlUpdate: json["last_ll_update"] == null
  123.             ? null
  124.             : DateTime.parse(json["last_ll_update"]),
  125.         lastWikiLaunchDate: json["last_wiki_launch_date"] == null
  126.             ? null
  127.             : DateTime.parse(json["last_wiki_launch_date"]),
  128.         lastWikiRevision: json["last_wiki_revision"] == null
  129.             ? null
  130.             : json["last_wiki_revision"],
  131.         lastWikiUpdate: json["last_wiki_update"] == null
  132.             ? null
  133.             : DateTime.parse(json["last_wiki_update"]),
  134.         launchDateSource: json["launch_date_source"] == null
  135.             ? null
  136.             : launchDateSourceValues.map[json["launch_date_source"]],
  137.       );
  138.  
  139.   Map<String, dynamic> toJson() => {
  140.         "flight_number": flightNumber,
  141.         "mission_name": missionName,
  142.         "mission_id": List<dynamic>.from(missionId.map((x) => x)),
  143.         "upcoming": upcoming,
  144.         "launch_year": launchYear,
  145.         "launch_date_unix": launchDateUnix,
  146.         "launch_date_utc": launchDateUtc.toIso8601String(),
  147.         "launch_date_local": launchDateLocal.toIso8601String(),
  148.         "is_tentative": isTentative,
  149.         "tentative_max_precision":
  150.             tentativeMaxPrecisionValues.reverse[tentativeMaxPrecision],
  151.         "tbd": tbd,
  152.         "launch_window": launchWindow == null ? null : launchWindow,
  153.         "rocket": rocket.toJson(),
  154.         "ships": List<dynamic>.from(ships.map((x) => x)),
  155.         "telemetry": telemetry.toJson(),
  156.         "reuse": reuse.toJson(),
  157.         "launch_site": launchSite.toJson(),
  158.         "launch_success": launchSuccess == null ? null : launchSuccess,
  159.         "launch_failure_details":
  160.             launchFailureDetails == null ? null : launchFailureDetails.toJson(),
  161.         "links": links.toJson(),
  162.         "details": details == null ? null : details,
  163.         "static_fire_date_utc": staticFireDateUtc == null
  164.             ? null
  165.             : staticFireDateUtc.toIso8601String(),
  166.         "static_fire_date_unix":
  167.             staticFireDateUnix == null ? null : staticFireDateUnix,
  168.         "timeline": timeline == null
  169.             ? null
  170.             : Map.from(timeline).map(
  171.                 (k, v) => MapEntry<String, dynamic>(k, v == null ? null : v)),
  172.         "crew": crew,
  173.         "last_date_update":
  174.             lastDateUpdate == null ? null : lastDateUpdate.toIso8601String(),
  175.         "last_ll_launch_date": lastLlLaunchDate == null
  176.             ? null
  177.             : lastLlLaunchDate.toIso8601String(),
  178.         "last_ll_update":
  179.             lastLlUpdate == null ? null : lastLlUpdate.toIso8601String(),
  180.         "last_wiki_launch_date": lastWikiLaunchDate == null
  181.             ? null
  182.             : lastWikiLaunchDate.toIso8601String(),
  183.         "last_wiki_revision":
  184.             lastWikiRevision == null ? null : lastWikiRevision,
  185.         "last_wiki_update":
  186.             lastWikiUpdate == null ? null : lastWikiUpdate.toIso8601String(),
  187.         "launch_date_source": launchDateSource == null
  188.             ? null
  189.             : launchDateSourceValues.reverse[launchDateSource],
  190.       };
  191. }
  192.  
  193. enum LaunchDateSource { WIKI, LAUNCH_LIBRARY }
  194.  
  195. final launchDateSourceValues = EnumValues({
  196.   "launch_library": LaunchDateSource.LAUNCH_LIBRARY,
  197.   "wiki": LaunchDateSource.WIKI
  198. });
  199.  
  200. class LaunchFailureDetails {
  201.   LaunchFailureDetails({
  202.     this.time,
  203.     this.altitude,
  204.     this.reason,
  205.   });
  206.  
  207.   int time;
  208.   int altitude;
  209.   String reason;
  210.  
  211.   factory LaunchFailureDetails.fromJson(Map<String, dynamic> json) =>
  212.       LaunchFailureDetails(
  213.         time: json["time"],
  214.         altitude: json["altitude"] == null ? null : json["altitude"],
  215.         reason: json["reason"],
  216.       );
  217.  
  218.   Map<String, dynamic> toJson() => {
  219.         "time": time,
  220.         "altitude": altitude == null ? null : altitude,
  221.         "reason": reason,
  222.       };
  223. }
  224.  
  225. class LaunchSite {
  226.   LaunchSite({
  227.     this.siteId,
  228.     this.siteName,
  229.     this.siteNameLong,
  230.   });
  231.  
  232.   SiteId siteId;
  233.   SiteName siteName;
  234.   SiteNameLong siteNameLong;
  235.  
  236.   factory LaunchSite.fromJson(Map<String, dynamic> json) => LaunchSite(
  237.         siteId: siteIdValues.map[json["site_id"]],
  238.         siteName: siteNameValues.map[json["site_name"]],
  239.         siteNameLong: siteNameLongValues.map[json["site_name_long"]],
  240.       );
  241.  
  242.   Map<String, dynamic> toJson() => {
  243.         "site_id": siteIdValues.reverse[siteId],
  244.         "site_name": siteNameValues.reverse[siteName],
  245.         "site_name_long": siteNameLongValues.reverse[siteNameLong],
  246.       };
  247. }
  248.  
  249. enum SiteId { KWAJALEIN_ATOLL, CCAFS_SLC_40, VAFB_SLC_4_E, KSC_LC_39_A }
  250.  
  251. final siteIdValues = EnumValues({
  252.   "ccafs_slc_40": SiteId.CCAFS_SLC_40,
  253.   "ksc_lc_39a": SiteId.KSC_LC_39_A,
  254.   "kwajalein_atoll": SiteId.KWAJALEIN_ATOLL,
  255.   "vafb_slc_4e": SiteId.VAFB_SLC_4_E
  256. });
  257.  
  258. enum SiteName { KWAJALEIN_ATOLL, CCAFS_SLC_40, VAFB_SLC_4_E, KSC_LC_39_A }
  259.  
  260. final siteNameValues = EnumValues({
  261.   "CCAFS SLC 40": SiteName.CCAFS_SLC_40,
  262.   "KSC LC 39A": SiteName.KSC_LC_39_A,
  263.   "Kwajalein Atoll": SiteName.KWAJALEIN_ATOLL,
  264.   "VAFB SLC 4E": SiteName.VAFB_SLC_4_E
  265. });
  266.  
  267. enum SiteNameLong {
  268.   KWAJALEIN_ATOLL_OMELEK_ISLAND,
  269.   CAPE_CANAVERAL_AIR_FORCE_STATION_SPACE_LAUNCH_COMPLEX_40,
  270.   VANDENBERG_AIR_FORCE_BASE_SPACE_LAUNCH_COMPLEX_4_E,
  271.   KENNEDY_SPACE_CENTER_HISTORIC_LAUNCH_COMPLEX_39_A
  272. }
  273.  
  274. final siteNameLongValues = EnumValues({
  275.   "Cape Canaveral Air Force Station Space Launch Complex 40":
  276.       SiteNameLong.CAPE_CANAVERAL_AIR_FORCE_STATION_SPACE_LAUNCH_COMPLEX_40,
  277.   "Kennedy Space Center Historic Launch Complex 39A":
  278.       SiteNameLong.KENNEDY_SPACE_CENTER_HISTORIC_LAUNCH_COMPLEX_39_A,
  279.   "Kwajalein Atoll Omelek Island": SiteNameLong.KWAJALEIN_ATOLL_OMELEK_ISLAND,
  280.   "Vandenberg Air Force Base Space Launch Complex 4E":
  281.       SiteNameLong.VANDENBERG_AIR_FORCE_BASE_SPACE_LAUNCH_COMPLEX_4_E
  282. });
  283.  
  284. class Links {
  285.   Links({
  286.     this.missionPatch,
  287.     this.missionPatchSmall,
  288.     this.redditCampaign,
  289.     this.redditLaunch,
  290.     this.redditRecovery,
  291.     this.redditMedia,
  292.     this.presskit,
  293.     this.articleLink,
  294.     this.wikipedia,
  295.     this.videoLink,
  296.     this.youtubeId,
  297.     this.flickrImages,
  298.   });
  299.  
  300.   String missionPatch;
  301.   String missionPatchSmall;
  302.   String redditCampaign;
  303.   String redditLaunch;
  304.   String redditRecovery;
  305.   String redditMedia;
  306.   String presskit;
  307.   String articleLink;
  308.   String wikipedia;
  309.   String videoLink;
  310.   String youtubeId;
  311.   List<String> flickrImages;
  312.  
  313.   factory Links.fromJson(Map<String, dynamic> json) => Links(
  314.         missionPatch: json["mission_patch"],
  315.         missionPatchSmall: json["mission_patch_small"],
  316.         redditCampaign:
  317.             json["reddit_campaign"] == null ? null : json["reddit_campaign"],
  318.         redditLaunch:
  319.             json["reddit_launch"] == null ? null : json["reddit_launch"],
  320.         redditRecovery:
  321.             json["reddit_recovery"] == null ? null : json["reddit_recovery"],
  322.         redditMedia: json["reddit_media"] == null ? null : json["reddit_media"],
  323.         presskit: json["presskit"] == null ? null : json["presskit"],
  324.         articleLink: json["article_link"] == null ? null : json["article_link"],
  325.         wikipedia: json["wikipedia"] == null ? null : json["wikipedia"],
  326.         videoLink: json["video_link"],
  327.         youtubeId: json["youtube_id"],
  328.         flickrImages: List<String>.from(json["flickr_images"].map((x) => x)),
  329.       );
  330.  
  331.   Map<String, dynamic> toJson() => {
  332.         "mission_patch": missionPatch,
  333.         "mission_patch_small": missionPatchSmall,
  334.         "reddit_campaign": redditCampaign == null ? null : redditCampaign,
  335.         "reddit_launch": redditLaunch == null ? null : redditLaunch,
  336.         "reddit_recovery": redditRecovery == null ? null : redditRecovery,
  337.         "reddit_media": redditMedia == null ? null : redditMedia,
  338.         "presskit": presskit == null ? null : presskit,
  339.         "article_link": articleLink == null ? null : articleLink,
  340.         "wikipedia": wikipedia == null ? null : wikipedia,
  341.         "video_link": videoLink,
  342.         "youtube_id": youtubeId,
  343.         "flickr_images": List<dynamic>.from(flickrImages.map((x) => x)),
  344.       };
  345. }
  346.  
  347. class Reuse {
  348.   Reuse({
  349.     this.core,
  350.     this.sideCore1,
  351.     this.sideCore2,
  352.     this.fairings,
  353.     this.capsule,
  354.   });
  355.  
  356.   bool core;
  357.   bool sideCore1;
  358.   bool sideCore2;
  359.   bool fairings;
  360.   bool capsule;
  361.  
  362.   factory Reuse.fromJson(Map<String, dynamic> json) => Reuse(
  363.         core: json["core"],
  364.         sideCore1: json["side_core1"],
  365.         sideCore2: json["side_core2"],
  366.         fairings: json["fairings"],
  367.         capsule: json["capsule"],
  368.       );
  369.  
  370.   Map<String, dynamic> toJson() => {
  371.         "core": core,
  372.         "side_core1": sideCore1,
  373.         "side_core2": sideCore2,
  374.         "fairings": fairings,
  375.         "capsule": capsule,
  376.       };
  377. }
  378.  
  379. class Rocket {
  380.   Rocket({
  381.     this.rocketId,
  382.     this.rocketName,
  383.     this.rocketType,
  384.     this.firstStage,
  385.     this.secondStage,
  386.     this.fairings,
  387.   });
  388.  
  389.   RocketId rocketId;
  390.   RocketName rocketName;
  391.   RocketType rocketType;
  392.   FirstStage firstStage;
  393.   SecondStage secondStage;
  394.   Fairings fairings;
  395.  
  396.   factory Rocket.fromJson(Map<String, dynamic> json) => Rocket(
  397.         rocketId: rocketIdValues.map[json["rocket_id"]],
  398.         rocketName: rocketNameValues.map[json["rocket_name"]],
  399.         rocketType: rocketTypeValues.map[json["rocket_type"]],
  400.         firstStage: FirstStage.fromJson(json["first_stage"]),
  401.         secondStage: SecondStage.fromJson(json["second_stage"]),
  402.         fairings: json["fairings"] == null
  403.             ? null
  404.             : Fairings.fromJson(json["fairings"]),
  405.       );
  406.  
  407.   Map<String, dynamic> toJson() => {
  408.         "rocket_id": rocketIdValues.reverse[rocketId],
  409.         "rocket_name": rocketNameValues.reverse[rocketName],
  410.         "rocket_type": rocketTypeValues.reverse[rocketType],
  411.         "first_stage": firstStage.toJson(),
  412.         "second_stage": secondStage.toJson(),
  413.         "fairings": fairings == null ? null : fairings.toJson(),
  414.       };
  415. }
  416.  
  417. class Fairings {
  418.   Fairings({
  419.     this.reused,
  420.     this.recoveryAttempt,
  421.     this.recovered,
  422.     this.ship,
  423.   });
  424.  
  425.   bool reused;
  426.   bool recoveryAttempt;
  427.   bool recovered;
  428.   Ship ship;
  429.  
  430.   factory Fairings.fromJson(Map<String, dynamic> json) => Fairings(
  431.         reused: json["reused"] == null ? null : json["reused"],
  432.         recoveryAttempt:
  433.             json["recovery_attempt"] == null ? null : json["recovery_attempt"],
  434.         recovered: json["recovered"] == null ? null : json["recovered"],
  435.         ship: json["ship"] == null ? null : shipValues.map[json["ship"]],
  436.       );
  437.  
  438.   Map<String, dynamic> toJson() => {
  439.         "reused": reused == null ? null : reused,
  440.         "recovery_attempt": recoveryAttempt == null ? null : recoveryAttempt,
  441.         "recovered": recovered == null ? null : recovered,
  442.         "ship": ship == null ? null : shipValues.reverse[ship],
  443.       };
  444. }
  445.  
  446. enum Ship { GOMSTREE, GOSEARCHER, GOMSCHIEF }
  447.  
  448. final shipValues = EnumValues({
  449.   "GOMSCHIEF": Ship.GOMSCHIEF,
  450.   "GOMSTREE": Ship.GOMSTREE,
  451.   "GOSEARCHER": Ship.GOSEARCHER
  452. });
  453.  
  454. class FirstStage {
  455.   FirstStage({
  456.     this.cores,
  457.   });
  458.  
  459.   List<Core> cores;
  460.  
  461.   factory FirstStage.fromJson(Map<String, dynamic> json) => FirstStage(
  462.         cores: List<Core>.from(json["cores"].map((x) => Core.fromJson(x))),
  463.       );
  464.  
  465.   Map<String, dynamic> toJson() => {
  466.         "cores": List<dynamic>.from(cores.map((x) => x.toJson())),
  467.       };
  468. }
  469.  
  470. class Core {
  471.   Core({
  472.     this.coreSerial,
  473.     this.flight,
  474.     this.block,
  475.     this.gridfins,
  476.     this.legs,
  477.     this.reused,
  478.     this.landSuccess,
  479.     this.landingIntent,
  480.     this.landingType,
  481.     this.landingVehicle,
  482.   });
  483.  
  484.   String coreSerial;
  485.   int flight;
  486.   int block;
  487.   bool gridfins;
  488.   bool legs;
  489.   bool reused;
  490.   bool landSuccess;
  491.   bool landingIntent;
  492.   LandingType landingType;
  493.   LandingVehicle landingVehicle;
  494.  
  495.   factory Core.fromJson(Map<String, dynamic> json) => Core(
  496.         coreSerial: json["core_serial"],
  497.         flight: json["flight"],
  498.         block: json["block"] == null ? null : json["block"],
  499.         gridfins: json["gridfins"],
  500.         legs: json["legs"],
  501.         reused: json["reused"],
  502.         landSuccess: json["land_success"] == null ? null : json["land_success"],
  503.         landingIntent: json["landing_intent"],
  504.         landingType: json["landing_type"] == null
  505.             ? null
  506.             : landingTypeValues.map[json["landing_type"]],
  507.         landingVehicle: json["landing_vehicle"] == null
  508.             ? null
  509.             : landingVehicleValues.map[json["landing_vehicle"]],
  510.       );
  511.  
  512.   Map<String, dynamic> toJson() => {
  513.         "core_serial": coreSerial,
  514.         "flight": flight,
  515.         "block": block == null ? null : block,
  516.         "gridfins": gridfins,
  517.         "legs": legs,
  518.         "reused": reused,
  519.         "land_success": landSuccess == null ? null : landSuccess,
  520.         "landing_intent": landingIntent,
  521.         "landing_type":
  522.             landingType == null ? null : landingTypeValues.reverse[landingType],
  523.         "landing_vehicle": landingVehicle == null
  524.             ? null
  525.             : landingVehicleValues.reverse[landingVehicle],
  526.       };
  527. }
  528.  
  529. enum LandingType { OCEAN, ASDS, RTLS }
  530.  
  531. final landingTypeValues = EnumValues({
  532.   "ASDS": LandingType.ASDS,
  533.   "Ocean": LandingType.OCEAN,
  534.   "RTLS": LandingType.RTLS
  535. });
  536.  
  537. enum LandingVehicle { JRTI_1, OCISLY, LZ_1, JRTI, LZ_2, LZ_4 }
  538.  
  539. final landingVehicleValues = EnumValues({
  540.   "JRTI": LandingVehicle.JRTI,
  541.   "JRTI-1": LandingVehicle.JRTI_1,
  542.   "LZ-1": LandingVehicle.LZ_1,
  543.   "LZ-2": LandingVehicle.LZ_2,
  544.   "LZ-4": LandingVehicle.LZ_4,
  545.   "OCISLY": LandingVehicle.OCISLY
  546. });
  547.  
  548. enum RocketId { FALCON1, FALCON9, FALCONHEAVY }
  549.  
  550. final rocketIdValues = EnumValues({
  551.   "falcon1": RocketId.FALCON1,
  552.   "falcon9": RocketId.FALCON9,
  553.   "falconheavy": RocketId.FALCONHEAVY
  554. });
  555.  
  556. enum RocketName { FALCON_1, FALCON_9, FALCON_HEAVY }
  557.  
  558. final rocketNameValues = EnumValues({
  559.   "Falcon 1": RocketName.FALCON_1,
  560.   "Falcon 9": RocketName.FALCON_9,
  561.   "Falcon Heavy": RocketName.FALCON_HEAVY
  562. });
  563.  
  564. enum RocketType { MERLIN_A, MERLIN_C, V1_0, V1_1, FT }
  565.  
  566. final rocketTypeValues = EnumValues({
  567.   "FT": RocketType.FT,
  568.   "Merlin A": RocketType.MERLIN_A,
  569.   "Merlin C": RocketType.MERLIN_C,
  570.   "v1.0": RocketType.V1_0,
  571.   "v1.1": RocketType.V1_1
  572. });
  573.  
  574. class SecondStage {
  575.   SecondStage({
  576.     this.block,
  577.     this.payloads,
  578.   });
  579.  
  580.   int block;
  581.   List<Payload> payloads;
  582.  
  583.   factory SecondStage.fromJson(Map<String, dynamic> json) => SecondStage(
  584.         block: json["block"] == null ? null : json["block"],
  585.         payloads: List<Payload>.from(
  586.             json["payloads"].map((x) => Payload.fromJson(x))),
  587.       );
  588.  
  589.   Map<String, dynamic> toJson() => {
  590.         "block": block == null ? null : block,
  591.         "payloads": List<dynamic>.from(payloads.map((x) => x.toJson())),
  592.       };
  593. }
  594.  
  595. class Payload {
  596.   Payload({
  597.     this.payloadId,
  598.     this.noradId,
  599.     this.reused,
  600.     this.customers,
  601.     this.nationality,
  602.     this.manufacturer,
  603.     this.payloadType,
  604.     this.payloadMassKg,
  605.     this.payloadMassLbs,
  606.     this.orbit,
  607.     this.orbitParams,
  608.     this.capSerial,
  609.     this.massReturnedKg,
  610.     this.massReturnedLbs,
  611.     this.flightTimeSec,
  612.     this.cargoManifest,
  613.     this.uid,
  614.   });
  615.  
  616.   String payloadId;
  617.   List<int> noradId;
  618.   bool reused;
  619.   List<String> customers;
  620.   String nationality;
  621.   String manufacturer;
  622.   PayloadType payloadType;
  623.   double payloadMassKg;
  624.   double payloadMassLbs;
  625.   String orbit;
  626.   OrbitParams orbitParams;
  627.   String capSerial;
  628.   double massReturnedKg;
  629.   double massReturnedLbs;
  630.   int flightTimeSec;
  631.   String cargoManifest;
  632.   String uid;
  633.  
  634.   factory Payload.fromJson(Map<String, dynamic> json) => Payload(
  635.         payloadId: json["payload_id"],
  636.         noradId: List<int>.from(json["norad_id"].map((x) => x)),
  637.         reused: json["reused"],
  638.         customers: List<String>.from(json["customers"].map((x) => x)),
  639.         nationality: json["nationality"] == null ? null : json["nationality"],
  640.         manufacturer:
  641.             json["manufacturer"] == null ? null : json["manufacturer"],
  642.         payloadType: payloadTypeValues.map[json["payload_type"]],
  643.         payloadMassKg: json["payload_mass_kg"] == null
  644.             ? null
  645.             : json["payload_mass_kg"].toDouble(),
  646.         payloadMassLbs: json["payload_mass_lbs"] == null
  647.             ? null
  648.             : json["payload_mass_lbs"].toDouble(),
  649.         orbit: json["orbit"],
  650.         orbitParams: OrbitParams.fromJson(json["orbit_params"]),
  651.         capSerial: json["cap_serial"] == null ? null : json["cap_serial"],
  652.         massReturnedKg: json["mass_returned_kg"] == null
  653.             ? null
  654.             : json["mass_returned_kg"].toDouble(),
  655.         massReturnedLbs: json["mass_returned_lbs"] == null
  656.             ? null
  657.             : json["mass_returned_lbs"].toDouble(),
  658.         flightTimeSec:
  659.             json["flight_time_sec"] == null ? null : json["flight_time_sec"],
  660.         cargoManifest:
  661.             json["cargo_manifest"] == null ? null : json["cargo_manifest"],
  662.         uid: json["uid"] == null ? null : json["uid"],
  663.       );
  664.  
  665.   Map<String, dynamic> toJson() => {
  666.         "payload_id": payloadId,
  667.         "norad_id": List<dynamic>.from(noradId.map((x) => x)),
  668.         "reused": reused,
  669.         "customers": List<dynamic>.from(customers.map((x) => x)),
  670.         "nationality": nationality == null ? null : nationality,
  671.         "manufacturer": manufacturer == null ? null : manufacturer,
  672.         "payload_type": payloadTypeValues.reverse[payloadType],
  673.         "payload_mass_kg": payloadMassKg == null ? null : payloadMassKg,
  674.         "payload_mass_lbs": payloadMassLbs == null ? null : payloadMassLbs,
  675.         "orbit": orbit,
  676.         "orbit_params": orbitParams.toJson(),
  677.         "cap_serial": capSerial == null ? null : capSerial,
  678.         "mass_returned_kg": massReturnedKg == null ? null : massReturnedKg,
  679.         "mass_returned_lbs": massReturnedLbs == null ? null : massReturnedLbs,
  680.         "flight_time_sec": flightTimeSec == null ? null : flightTimeSec,
  681.         "cargo_manifest": cargoManifest == null ? null : cargoManifest,
  682.         "uid": uid == null ? null : uid,
  683.       };
  684. }
  685.  
  686. class OrbitParams {
  687.   OrbitParams({
  688.     this.referenceSystem,
  689.     this.regime,
  690.     this.longitude,
  691.     this.semiMajorAxisKm,
  692.     this.eccentricity,
  693.     this.periapsisKm,
  694.     this.apoapsisKm,
  695.     this.inclinationDeg,
  696.     this.periodMin,
  697.     this.lifespanYears,
  698.     this.epoch,
  699.     this.meanMotion,
  700.     this.raan,
  701.     this.argOfPericenter,
  702.     this.meanAnomaly,
  703.   });
  704.  
  705.   ReferenceSystem referenceSystem;
  706.   Regime regime;
  707.   double longitude;
  708.   double semiMajorAxisKm;
  709.   double eccentricity;
  710.   double periapsisKm;
  711.   double apoapsisKm;
  712.   double inclinationDeg;
  713.   double periodMin;
  714.   double lifespanYears;
  715.   DateTime epoch;
  716.   double meanMotion;
  717.   double raan;
  718.   double argOfPericenter;
  719.   double meanAnomaly;
  720.  
  721.   factory OrbitParams.fromJson(Map<String, dynamic> json) => OrbitParams(
  722.         referenceSystem: json["reference_system"] == null
  723.             ? null
  724.             : referenceSystemValues.map[json["reference_system"]],
  725.         regime:
  726.             json["regime"] == null ? null : regimeValues.map[json["regime"]],
  727.         longitude:
  728.             json["longitude"] == null ? null : json["longitude"].toDouble(),
  729.         semiMajorAxisKm: json["semi_major_axis_km"] == null
  730.             ? null
  731.             : json["semi_major_axis_km"].toDouble(),
  732.         eccentricity: json["eccentricity"] == null
  733.             ? null
  734.             : json["eccentricity"].toDouble(),
  735.         periapsisKm: json["periapsis_km"] == null
  736.             ? null
  737.             : json["periapsis_km"].toDouble(),
  738.         apoapsisKm:
  739.             json["apoapsis_km"] == null ? null : json["apoapsis_km"].toDouble(),
  740.         inclinationDeg: json["inclination_deg"] == null
  741.             ? null
  742.             : json["inclination_deg"].toDouble(),
  743.         periodMin:
  744.             json["period_min"] == null ? null : json["period_min"].toDouble(),
  745.         lifespanYears: json["lifespan_years"] == null
  746.             ? null
  747.             : json["lifespan_years"].toDouble(),
  748.         epoch: json["epoch"] == null ? null : DateTime.parse(json["epoch"]),
  749.         meanMotion:
  750.             json["mean_motion"] == null ? null : json["mean_motion"].toDouble(),
  751.         raan: json["raan"] == null ? null : json["raan"].toDouble(),
  752.         argOfPericenter: json["arg_of_pericenter"] == null
  753.             ? null
  754.             : json["arg_of_pericenter"].toDouble(),
  755.         meanAnomaly: json["mean_anomaly"] == null
  756.             ? null
  757.             : json["mean_anomaly"].toDouble(),
  758.       );
  759.  
  760.   Map<String, dynamic> toJson() => {
  761.         "reference_system": referenceSystem == null
  762.             ? null
  763.             : referenceSystemValues.reverse[referenceSystem],
  764.         "regime": regime == null ? null : regimeValues.reverse[regime],
  765.         "longitude": longitude == null ? null : longitude,
  766.         "semi_major_axis_km": semiMajorAxisKm == null ? null : semiMajorAxisKm,
  767.         "eccentricity": eccentricity == null ? null : eccentricity,
  768.         "periapsis_km": periapsisKm == null ? null : periapsisKm,
  769.         "apoapsis_km": apoapsisKm == null ? null : apoapsisKm,
  770.         "inclination_deg": inclinationDeg == null ? null : inclinationDeg,
  771.         "period_min": periodMin == null ? null : periodMin,
  772.         "lifespan_years": lifespanYears == null ? null : lifespanYears,
  773.         "epoch": epoch == null ? null : epoch.toIso8601String(),
  774.         "mean_motion": meanMotion == null ? null : meanMotion,
  775.         "raan": raan == null ? null : raan,
  776.         "arg_of_pericenter": argOfPericenter == null ? null : argOfPericenter,
  777.         "mean_anomaly": meanAnomaly == null ? null : meanAnomaly,
  778.       };
  779. }
  780.  
  781. enum ReferenceSystem { GEOCENTRIC, HELIOCENTRIC, HIGHLY_ELLIPTICAL }
  782.  
  783. final referenceSystemValues = EnumValues({
  784.   "geocentric": ReferenceSystem.GEOCENTRIC,
  785.   "heliocentric": ReferenceSystem.HELIOCENTRIC,
  786.   "highly-elliptical": ReferenceSystem.HIGHLY_ELLIPTICAL
  787. });
  788.  
  789. enum Regime {
  790.   LOW_EARTH,
  791.   GEOSTATIONARY,
  792.   L1_POINT,
  793.   GEOSYNCHRONOUS,
  794.   SUN_SYNCHRONOUS,
  795.   HIGH_EARTH,
  796.   SEMI_SYNCHRONOUS,
  797.   HIGHLY_ELLIPTICAL,
  798.   VERY_LOW_EARTH,
  799.   MEDIUM_EARTH,
  800.   SUB_ORBITAL
  801. }
  802.  
  803. final regimeValues = EnumValues({
  804.   "geostationary": Regime.GEOSTATIONARY,
  805.   "geosynchronous": Regime.GEOSYNCHRONOUS,
  806.   "highly-elliptical": Regime.HIGHLY_ELLIPTICAL,
  807.   "high-earth": Regime.HIGH_EARTH,
  808.   "L1-point": Regime.L1_POINT,
  809.   "low-earth": Regime.LOW_EARTH,
  810.   "medium-earth": Regime.MEDIUM_EARTH,
  811.   "semi-synchronous": Regime.SEMI_SYNCHRONOUS,
  812.   "sub-orbital": Regime.SUB_ORBITAL,
  813.   "sun-synchronous": Regime.SUN_SYNCHRONOUS,
  814.   "very-low-earth": Regime.VERY_LOW_EARTH
  815. });
  816.  
  817. enum PayloadType {
  818.   SATELLITE,
  819.   DRAGON_BOILERPLATE,
  820.   DRAGON_10,
  821.   DRAGON_11,
  822.   LANDER,
  823.   CREW_DRAGON
  824. }
  825.  
  826. final payloadTypeValues = EnumValues({
  827.   "Crew Dragon": PayloadType.CREW_DRAGON,
  828.   "Dragon 1.0": PayloadType.DRAGON_10,
  829.   "Dragon 1.1": PayloadType.DRAGON_11,
  830.   "Dragon Boilerplate": PayloadType.DRAGON_BOILERPLATE,
  831.   "Lander": PayloadType.LANDER,
  832.   "Satellite": PayloadType.SATELLITE
  833. });
  834.  
  835. class Telemetry {
  836.   Telemetry({
  837.     this.flightClub,
  838.   });
  839.  
  840.   String flightClub;
  841.  
  842.   factory Telemetry.fromJson(Map<String, dynamic> json) => Telemetry(
  843.         flightClub: json["flight_club"] == null ? null : json["flight_club"],
  844.       );
  845.  
  846.   Map<String, dynamic> toJson() => {
  847.         "flight_club": flightClub == null ? null : flightClub,
  848.       };
  849. }
  850.  
  851. enum TentativeMaxPrecision { HOUR }
  852.  
  853. final tentativeMaxPrecisionValues =
  854.     EnumValues({"hour": TentativeMaxPrecision.HOUR});
  855.  
  856. class EnumValues<T> {
  857.   Map<String, T> map;
  858.   Map<T, String> reverseMap;
  859.  
  860.   EnumValues(this.map);
  861.  
  862.   Map<T, String> get reverse {
  863.     if (reverseMap == null) {
  864.       reverseMap = map.map((k, v) => new MapEntry(v, k));
  865.     }
  866.     return reverseMap;
  867.   }
  868. }
  869.  
Advertisement
Add Comment
Please, Sign In to add comment