-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
294 additions
and
39 deletions.
There are no files selected for viewing
Submodule eddn
updated
3 files
+11 −13 | examples/journal.rs | |
+20 −0 | examples/other.rs | |
+6 −11 | src/lib.rs |
Submodule elite_journal
updated
13 files
+3 −4 | src/body.rs | |
+12 −7 | src/de.rs | |
+4 −5 | src/entry/incremental/exploration.rs | |
+3 −5 | src/entry/incremental/mod.rs | |
+5 −3 | src/entry/incremental/travel.rs | |
+30 −21 | src/entry/mod.rs | |
+4 −4 | src/entry/route.rs | |
+81 −40 | src/faction.rs | |
+39 −24 | src/lib.rs | |
+4 −4 | src/prelude.rs | |
+1 −1 | src/ship.rs | |
+42 −11 | src/station.rs | |
+65 −37 | src/system.rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use sqlx::types::chrono::Utc; | ||
use elite_journal::station::{Station as JournalStation, StationType, Service}; | ||
use elite_journal::faction::Faction; | ||
use elite_journal::{Allegiance, Government}; | ||
use elite_journal::system::{System as JournalSystem, Coordinate}; | ||
use galos_db::systems::System; | ||
use galos_db::stations::Station; | ||
use galos_db::{Database, Error}; | ||
|
||
#[async_std::main] | ||
async fn main() -> Result<(), Error> { | ||
let db = Database::new().await?; | ||
let system_address = 0; | ||
let system = JournalSystem::new(system_address, "The Sun"); | ||
System::from_journal(&db, Utc::now(), &system).await; | ||
let station = JournalStation { | ||
dist_from_star_ls: None, | ||
name: "Maxland".into(), | ||
ty: Some(StationType::Orbis), | ||
market_id: Some(1), | ||
faction: Some(Faction { name: "Ours".into(), state: None }), | ||
government: Some(Government::Theocracy), | ||
allegiance: Some(Allegiance::PlayerPilots), | ||
services: Some(vec![Service::Contacts]), | ||
economies: None, | ||
wanted: None, | ||
}; | ||
let station = Station::from_journal(&db, | ||
Utc::now(), | ||
&station, | ||
system_address).await?; | ||
println!("{:#?}", station); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
CREATE TYPE StationType AS ENUM ( | ||
'AsteroidBase', | ||
'Coriolis', | ||
'CraterOutpost', | ||
'CraterPort', | ||
'FleetCarrier', | ||
'MegaShip', | ||
'Ocellus', | ||
'Orbis', | ||
'Outpost' | ||
); | ||
|
||
|
||
CREATE TYPE Service AS ENUM ( | ||
'Autodock', | ||
'Blackmarket', | ||
'CarrierFuel', | ||
'CarrierManagement', | ||
'Commodities', | ||
'Contacts', | ||
'CrewLounge', | ||
'Dock', | ||
'Engineer', | ||
'Exploration', | ||
'Facilitator', | ||
'FlightController', | ||
'Initiatives', | ||
'MaterialTrader', | ||
'Missions', | ||
'MissionsGenerated', | ||
'Modulepacks', | ||
'Outfitting', | ||
'Powerplay', | ||
'Rearm', | ||
'Refuel', | ||
'Repair', | ||
'SearchRescue', | ||
'Shipyard', | ||
'Shop', | ||
'StationMenu', | ||
'StationOperations', | ||
'TechBroker', | ||
'Tuning', | ||
'VoucherRedemption', | ||
'Livery', | ||
'SocialSpace', | ||
'Bartender', | ||
'VistaGenomics', | ||
'PioneerSupplies', | ||
'ApexInterstellar', | ||
'FrontlineSolutions' | ||
); | ||
|
||
CREATE TYPE EconomyShare AS ( | ||
name Economy, | ||
proportion double precision | ||
); | ||
|
||
CREATE TABLE stations ( | ||
system_address bigint REFERENCES systems NOT NULL, | ||
name varchar NOT NULL, | ||
ty StationType NOT NULL, | ||
market_id bigint, | ||
faction varchar, | ||
government Government, | ||
allegiance Allegiance, | ||
services Service[], | ||
economies EconomyShare[], | ||
updated_at timestamp NOT NULL, | ||
|
||
|
||
FOREIGN KEY (system_address) REFERENCES systems (address), | ||
PRIMARY KEY(system_address, name) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,3 +51,4 @@ pub mod articles; | |
pub mod bodies; | ||
pub mod factions; | ||
pub mod systems; | ||
pub mod stations; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
use crate::{Database, Error}; | ||
use chrono::{DateTime, Utc}; | ||
use elite_journal::station::Station as JournalStation; | ||
use elite_journal::station::{StationType, Service, EconomyShare}; | ||
use elite_journal::{Government, Allegiance}; | ||
|
||
#[derive(Debug, PartialEq, Eq)] | ||
pub struct Station { | ||
pub system_address: i64, | ||
pub name: String, | ||
pub ty: Option<StationType>, | ||
pub market_id: Option<i64>, | ||
pub faction: Option<String>, // TODO: Faction type? | ||
pub government: Option<Government>, // TODO: Government type? | ||
pub allegiance: Option<Allegiance>, | ||
pub services: Option<Vec<Service>>, | ||
pub economies: Option<Vec<EconomyShare>>, | ||
pub updated_at: DateTime<Utc>, | ||
} | ||
|
||
impl Station { | ||
pub async fn from_journal( | ||
db: &Database, | ||
timestamp: DateTime<Utc>, | ||
station: &JournalStation, | ||
system_address: i64, | ||
) -> Result<Station, Error> { | ||
let row = sqlx::query!( | ||
r#" | ||
INSERT INTO stations ( | ||
system_address, | ||
name, | ||
ty, | ||
market_id, | ||
faction, | ||
government, | ||
allegiance, | ||
services, | ||
economies, | ||
updated_at) | ||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) | ||
ON CONFLICT (system_address, name) | ||
DO UPDATE SET | ||
ty = $3, | ||
market_id = $4, | ||
faction = $5, | ||
government = $6, | ||
allegiance = $7, | ||
services = $8, | ||
economies = $9, | ||
updated_at = $10 | ||
RETURNING | ||
system_address, | ||
name, | ||
ty as "ty: StationType", | ||
market_id, | ||
faction, | ||
government as "government: Government", | ||
allegiance as "allegiance: Allegiance", | ||
services as "services: Vec<Service>", | ||
economies as "economies: Vec<EconomyShare>", | ||
updated_at | ||
"#, | ||
system_address, | ||
station.name, | ||
station.ty.clone() as Option<StationType>, | ||
station.market_id, | ||
station.faction.as_ref().map(|f| f.name.clone()), | ||
station.government as Option<Government>, | ||
station.allegiance as Option<Allegiance>, | ||
station.services.clone() as Option<Vec<Service>>, | ||
station.economies.clone() as Option<Vec<EconomyShare>>, | ||
timestamp.naive_utc(), | ||
) | ||
.fetch_one(&db.pool) | ||
.await?; | ||
|
||
Ok(Station { | ||
system_address: row.system_address, | ||
name: row.name, | ||
ty: Some(row.ty), | ||
market_id: row.market_id, | ||
faction: row.faction, | ||
government: row.government, | ||
allegiance: row.allegiance, | ||
services: row.services, | ||
economies: row.economies, | ||
updated_at: row.updated_at.and_utc(), | ||
}) | ||
} | ||
|
||
// pub async fn fetch(db: &Database, system_address: i64, name: &str) -> Result<Self, Error> { | ||
// let row = sqlx::query!( | ||
// " | ||
// SELECT * | ||
// FROM stations | ||
// WHERE system_address = $1 AND name = $2 | ||
// ", | ||
// system_address, | ||
// name | ||
// ) | ||
// .fetch_one(&db.pool) | ||
// .await?; | ||
|
||
// Ok(Station { | ||
// system_address: row.system_address, | ||
// name: row.name, | ||
// ty: row.ty, | ||
// market_id: row.market_id, | ||
// faction: row.faction, | ||
// government: row.government, | ||
// allegiance: row.allegiance, | ||
// services: row.services, | ||
// updated_at: row.updated_at.and_utc(), | ||
// }) | ||
// } | ||
} |
Oops, something went wrong.