Skip to content

Commit

Permalink
Merge pull request #3 from Austin-Scott/Experimental2
Browse files Browse the repository at this point in the history
Added features for version 1.2
  • Loading branch information
Austin-Scott authored Apr 7, 2018
2 parents b2b4196 + 10e87be commit 29b1a29
Show file tree
Hide file tree
Showing 9 changed files with 350 additions and 133 deletions.
1 change: 1 addition & 0 deletions EntityRelationDiagram.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0" version="8.5.7" editor="www.draw.io" type="device"><diagram id="65d115fb-d40e-e384-cb1e-b3a763ab18a7" name="Page-1">7V1tk5s2EP41nmm/dHg1+GPsS9JO75JMnZm2H2XQGRqMPELOnfPrK0Cy4SRiOwYJ53S5mRxCvGl3H+2zu4KJu9g8v8dgmzygGGYTx4qfJ+7dxHFsz5nS/8qWfd0SWnbdsMZpzDodG5bpN8gaLda6S2NYtDoShDKSbtuNEcpzGJFWG8AYPbW7PaKsfdUtWEOhYRmBTGz9O41Jwp7Ct47tv8N0nfAr2xbbswLRlzVGu5xdb+K4j9VPvXsD+LlY/yIBMXpqNLlvJ+4CI0TqvzbPC5iVY8uHrT7uXcfew31jmJNzDnDqA76CbMcefY5QQSBmt0f2fEiKp3STgZxuzR9RTpZsj0W3oyTN4nuwR7vymgWhY8C35gnC6TfaH2R0l00b6G5MmMSpmtCzpVm2QBnC1XVcaJX/WkcuyzOya2FY0GM/8Qe0XzQ9gOdWx3tQEH6XKMvAtkhX1X2XB24AXqf5HBGCNqwTf8p37ZtiMnTnIEvXOW2L6LXoILGxqJ/G9ug2G0+ICXzulIl9kDS1IIg2kOA97cIO8H1mPQfjqTefjppoz1hb0tRCy2MWwLR/fTj1UQPoH0wJ5AoxFRQiSgD+xf914r6h7Uw7/rgT9SMB2/JP+pwkBdlf1CxBvi73zgnasuHN4CMXB2Y3Xv694iKwG0Nc952XQ5lSy3zDmquTtZQmR5VWFlsQpfn6vr6E6x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+CgADC3UOQFKxOhgsiKkiAwtDwIKrj1uIoacX2cBdHiU3kgw0EFEdIaszHAwizBI4NfxC3xK4aShI9DbThGw2a6YJu0LAvecJA0k9LthnCMSiuZg84URNntDmb0DpfjWFHDjdHlYDBeekAAaM6r2+HMDlOcKgY2WhhhxhYF5PoSPsH+gL+4f66wiMa36ha34CMFTmCUOR2Zk84fCAEeorKghEwKjcCY/nADCgnvQSYipo41PcAl6ozBQGBi+0OBj68CIUYzciA/mIVykx3sUtoIXSlGFoCguUBP5CfYUFvBi6i4CwANYDMJmBGwEIlcnDUEw4G4AYAiAcfQAh5ofFwsTlbrvNUhOhuBGIUJk8DM0aQzUQcXqN4VAQMevmGMfiRBbJvJGXDxigqI7g3qEKoJgZsqEEKGYayYaYDm2RjQWGTw+wTHUYsnETAOFYCoOXoXlviRpPQl86dOYJEr3JMiSe1tVShjQTPe46KyRai6lCmqipQnJeVCF5kijNcF/ImXV8IocnDet0oXlZgd5CpNnFhUiDvdV+ZgqRzp9s+8sTzjTOvGJdgVlgOH7//ARmqPxQzkysLTCIMQR/11dMcPhmZNdKovpLWm+iyp81jsQNIITKb+XYlgnxKYEIZqeaMEKU6U1y+EDC4bsctN45vG2JmXW2TFP6IndD5BUReY+nKRh+TiWvHZQCKFen67SiOxlvXik2DhbPLHcUNN625F8IMVPusDye2amm+bd7zeGxYOceRcDQ+NE46adAQyWPty2TZ1PkpesL99m29XN46fwlq00vvRN+r3XT6SZGiDT2vcdgmzygGJY9/gc=</diagram></mxfile>
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Austin Scott

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
# SpaceX-Simulation
Creates data to populate a simple database for my Databases class. First it uses [Curl](https://curl.haxx.se/) to download a complete SpaceX mission manifest from [this open source REST API](https://github.com/r-spacex/SpaceX-API). Then it parses the downloaded JSON data using the [RapidJSON Library](http://rapidjson.org/). Afterwards, it performs a simulation to generate hypothetical future launch data. Many variables are simulated such as maximum reflights of cores, payload masses limited to launch configuration limits for any destination orbit, and dates that follow real world calendar rules such as everything from months having the correct number of days to properly handling leap years. Finally, the program outputs the conglomeration of real world and simulated data into a database by either directly connecting to the database or by printing out the results into a text file that can be read into the database manually.

## Dependencies
## Entity Relation Diagram
![entityrelationdiagram](https://user-images.githubusercontent.com/12504656/38458013-021c88a4-3a5e-11e8-926c-0671244fb9c2.png)

### Dependencies
* Boost 1.66.0 installed to "C:\Program Files\boost_1_66_0"
* MySQL Connector C++ 1.1.9 installed to "C:\Program Files\MySQL\MySQL Connector C++ 1.1.9"
* RapidJSON (Included with repository)

Once built, you must have the command line utility Curl downloaded, installed, and added to your PATH variable for the program to collect any real world data. If you don't install Curl the program will run just fine but all the data outputed will come only from the simulation.

### Command line arguments
This program has a couple of optional command line arguments to be used.
* -count can be used to specify how many missions you want the program to generate. The following example tells the program to generate 2500 missions: "SpaceX-Simulation -count 2500"
* -database can be used to connect directly to the database where you want the results to be stored. Immediately following this switch you must specify the address of the database, the schema to be used, the username, and the password exactly in that order. Here is an example usage: "SpaceX-Simulation -database tcp://127.0.0.1:3306 db1 root password"
This program has a handful of optional command line arguments to be used.
~~~~
Usage:
SpaceX-Simulation [options]
Options:
-h | --help #Prints help text and aborts program
-count <number_of_missions_to_generate> #Sets the number of simulated missions to generate
-skip #Skip manifest download. Only performs simulation.
-database <address> <schema> <username> <password> #Loads data directly into the specified database
-soft #If loading into database, drop only tuples not tables
-exclusive #If loading into database, do so exclusively. Skip txt files.
~~~~

### Goals for future versions
* Add more quantitative attributes to the tables
* Add more diversity to all the generated descriptions
* Add BFR colony missions to the simulation
* Add more payload types to reduce repitition in the generated missions
4 changes: 4 additions & 0 deletions SpaceX-Simulation/MySQL.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ sql::ResultSet* executeQuery(string query) {
return nullptr;
}

bool isSQLConnected() {
return con != nullptr;
}

void executeSQL(string statement) {
try {
stmt->execute(statement);
Expand Down
59 changes: 33 additions & 26 deletions SpaceX-Simulation/RealData.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ int getInt(const Value &parent, string name) {
return result;
}

bool getBool(const Value &parent, string name) {
bool result = false;
int getBool(const Value &parent, string name) {
int result = -1;
auto iter = parent.FindMember(name.c_str());
if (iter != parent.MemberEnd()) {
auto &member = iter->value;
if (!member.IsNull() && member.IsBool()) {
result = member.GetBool();
result = member.GetBool()?1:0;
}
}
return result;
Expand All @@ -88,7 +88,7 @@ void parseMissionData(const Value &mission) {
if (flight_number > highestMissionNumber) highestMissionNumber = flight_number;
Date launch_date(getString(mission, "launch_date_utc").substr(0,10));
string Description = getString(mission, "details");
bool launch_success = getBool(mission, "launch_success");
int launch_success = getBool(mission, "launch_success");
string rocket_id;
string Title; //Assigned by name of primary payload
string site_id;
Expand All @@ -100,7 +100,7 @@ void parseMissionData(const Value &mission) {
site_description = getString(launch_site_value, "site_name_long");
}
LaunchSite* current_launch_site = findOrCreateLaunchSite(site_id, site_description);
Mission* current_mission = createMission(flight_number, "TBD", Description, launch_date, current_launch_site);
Mission* current_mission = createMission(flight_number, "TBD", Description, launch_date, current_launch_site, launch_success);
auto rocket = mission.FindMember("rocket");
if (rocket != mission.MemberEnd()) {
auto &rocket_value = rocket->value;
Expand All @@ -115,15 +115,19 @@ void parseMissionData(const Value &mission) {
for (int i = 0; i < cores_value.Size(); i++) {
string core_serial = getString(cores_value[i], "core_serial");
int block = getInt(cores_value[i], "block");
bool land_success = getBool(cores_value[i], "land_success");
int land_success = getBool(cores_value[i], "land_success");
string landing_site = getString(cores_value[i], "landing_vehicle");
Booster* booster = findBooster(core_serial);
if (booster == nullptr) {
booster = createBooster(core_serial, land_success ? "Flight Operational" : "Destroyed", block);
string status = "";
if (land_success == 0) status = "Destroyed";
else if (land_success == 1) status = "Flight Operational";
else status = "Expended";
booster = createBooster(core_serial, status, block);
booster->flights = 0;
}
booster->flights++;
createFlownBy(booster, current_mission, landing_site, land_success ? "Booster recovered nominally." : "Rapid unscheduled disassembly.");
createFlownBy(booster, current_mission, landing_site, land_success==1 ? "Booster recovered nominally." : "Booster destroyed", land_success);
}
}
}
Expand All @@ -142,7 +146,7 @@ void parseMissionData(const Value &mission) {
string cap_serial = getString(payloads_value[i], "cap_serial");
Dragon* capsule = findDragon(cap_serial);
if (capsule == nullptr && cap_serial.size()>0) {
capsule = createDragon(cap_serial, "Dragon Capsule");
capsule = createDragon(cap_serial, "Dragon Capsule", 1);
}
string supplier;
auto customers = payloads_value[i].FindMember("customers");
Expand All @@ -156,7 +160,7 @@ void parseMissionData(const Value &mission) {
Title = payload_id;
strcpy(Title, current_mission->Title, 255);
}
createPayload(payload_id, orbit, payload_mass, supplier, launch_success ? "Complete success." : "Mission failed.", capsule, current_mission);
createPayload(payload_id, orbit, payload_mass, supplier, launch_success==1 ? "Complete success." : "Mission failed.", capsule, current_mission, 0);
}
}
}
Expand Down Expand Up @@ -210,36 +214,39 @@ void prepareCapsuleForSimulation(Dragon* capsule) {
if (getString(doc, "status") == "active") {
flightActiveDragons.addVehicle(capsule);
}
else {
capsule->FlightActive = 0;
}
}

void addFalconOneLaunches() {
LaunchSite* site = createLaunchSite("kwajalein_atoll", "Kwajalein Atoll Omelek Island");
//Flight One
Mission* flightOne = createMission(1, "Falcon One Flight One", "Engine failure at 33 seconds and loss of vehicle", Date("2006-03-24"), site);
Mission* flightOne = createMission(1, "Falcon One Flight One", "Engine failure at 33 seconds and loss of vehicle", Date("2006-03-24"), site, 0);
Booster* booster1 = createBooster("00001", "Destroyed", 0);
flownBy* f1 = createFlownBy(booster1, flightOne, "", "");
Payload* p1 = createPayload("FalconSAT-2", "LEO", 20, "DARPA", "Failed", nullptr, flightOne);
flownBy* f1 = createFlownBy(booster1, flightOne, "", "", -1);
Payload* p1 = createPayload("FalconSAT-2", "LEO", 20, "DARPA", "Failed", nullptr, flightOne, 0);
//Flight Two
Mission* flightTwo = createMission(2, "Falcon One Flight Two", "Successful first stage burn and transition to second stage, maximum altitude 289 km, Premature engine shutdown at T+7 min 30 s, Failed to reach orbit, Failed to recover first stage", Date("2007-03-21"), site);
Mission* flightTwo = createMission(2, "Falcon One Flight Two", "Successful first stage burn and transition to second stage, maximum altitude 289 km, Premature engine shutdown at T+7 min 30 s, Failed to reach orbit, Failed to recover first stage", Date("2007-03-21"), site, 0);
Booster* booster2 = createBooster("00002", "Expended", 0);
flownBy* f2 = createFlownBy(booster2, flightTwo, "", "");
Payload* p2 = createPayload("DemoSAT", "LEO", INT_MIN, "DARPA", "Failed", nullptr, flightTwo);
flownBy* f2 = createFlownBy(booster2, flightTwo, "", "", -1);
Payload* p2 = createPayload("DemoSAT", "LEO", INT_MIN, "DARPA", "Failed", nullptr, flightTwo, 0);
//Flight Three
Mission* flightThree = createMission(3, "Falcon One Flight Three", "Residual stage 1 thrust led to collision between stage 1 and stage 2", Date("2008-08-02"), site);
Mission* flightThree = createMission(3, "Falcon One Flight Three", "Residual stage 1 thrust led to collision between stage 1 and stage 2", Date("2008-08-02"), site, 0);
Booster* booster3 = createBooster("00003", "Destroyed", 0);
flownBy* f3 = createFlownBy(booster3, flightThree, "", "");
Payload* p3 = createPayload("Trailblazer", "LEO", INT_MIN, "NASA", "Failed", nullptr, flightThree);
Payload* p4 = createPayload("PRESat", "LEO", INT_MIN, "ORS", "Failed", nullptr, flightThree);
flownBy* f3 = createFlownBy(booster3, flightThree, "", "", -1);
Payload* p3 = createPayload("Trailblazer", "LEO", INT_MIN, "NASA", "Failed", nullptr, flightThree, 0);
Payload* p4 = createPayload("PRESat", "LEO", INT_MIN, "ORS", "Failed", nullptr, flightThree, 0);
//Flight Four
Mission* flightFour = createMission(4, "Falcon One Flight Four", "Ratsat was carried to orbit on the first successful orbital launch of any privately funded and developed, liquid-propelled carrier rocket, the SpaceX Falcon 1", Date("2008-09-28"), site);
Mission* flightFour = createMission(4, "Falcon One Flight Four", "Ratsat was carried to orbit on the first successful orbital launch of any privately funded and developed, liquid-propelled carrier rocket, the SpaceX Falcon 1", Date("2008-09-28"), site, 1);
Booster* booster4 = createBooster("00004", "Expended", 0);
flownBy* f4 = createFlownBy(booster4, flightFour, "", "");
Payload* p5 = createPayload("RatSat", "LEO", 165, "SpaceX", "Success", nullptr, flightFour);
flownBy* f4 = createFlownBy(booster4, flightFour, "", "", -1);
Payload* p5 = createPayload("RatSat", "LEO", 165, "SpaceX", "Success", nullptr, flightFour, 0);
//Flight Five
Mission* flightFive = createMission(5, "Falcon One Flight Five", "Fifth and final flight of Falcon One", Date("2009-07-13"), site);
Mission* flightFive = createMission(5, "Falcon One Flight Five", "Fifth and final flight of Falcon One", Date("2009-07-13"), site, 1);
Booster* booster5 = createBooster("00005", "Expended", 0);
flownBy* f5 = createFlownBy(booster5, flightFive, "", "");
Payload* p6 = createPayload("RazakSAT", "LEO", 200, "ATSB", "Success", nullptr, flightFive);
flownBy* f5 = createFlownBy(booster5, flightFive, "", "", -1);
Payload* p6 = createPayload("RazakSAT", "LEO", 200, "ATSB", "Success", nullptr, flightFive, 0);
}

void getRealData() {
Expand Down
Loading

0 comments on commit 29b1a29

Please sign in to comment.