clean: make line length consistent to 120

This commit is contained in:
realaltffour 2020-07-31 12:59:52 +03:00
parent 442ec5cd1a
commit 1c725e28a4
No known key found for this signature in database
GPG Key ID: C1265D839D44DCB1
8 changed files with 23 additions and 11 deletions

View File

@ -33,13 +33,15 @@ pub fn get_stock_from_db(state: &mut GlobalState, searched_symbol: String) -> Re
/*
* Returns all stock values from database since a time epoch.
*/
pub fn get_stock_from_db_since_epoch(state: &mut GlobalState, searched_symbol: String, time_epoch: i64) -> Result<Vec<StockVal>, String> {
pub fn get_stock_from_db_since_epoch(state: &mut GlobalState, searched_symbol: String,
time_epoch: i64) -> Result<Vec<StockVal>, String> {
// Connect to database.
let mut client = db_connect(state, DB_USER, DB_PASS)?;
// Query database for table.
let mut stocks: Vec<StockVal> = Vec::new();
match client.query(format!("SELECT * FROM asset_schema.{} WHERE time_since_epoch >= {}", searched_symbol, time_epoch).as_str(), &[]) {
match client.query(format!("SELECT * FROM asset_schema.{} WHERE time_since_epoch >= {}", searched_symbol,
time_epoch).as_str(), &[]) {
Ok(all_rows) => {
for row in all_rows {
let mut val: StockVal = StockVal::default();
@ -60,13 +62,15 @@ pub fn get_stock_from_db_since_epoch(state: &mut GlobalState, searched_symbol: S
/*
* Returns all stock values from database between two time epochs.
*/
pub fn get_stock_from_db_between_epochs(state: &mut GlobalState, searched_symbol: String, first_time_epoch: i64, second_time_epoch: i64) -> Result<Vec<StockVal>, String> {
pub fn get_stock_from_db_between_epochs(state: &mut GlobalState, searched_symbol: String, first_time_epoch: i64,
second_time_epoch: i64) -> Result<Vec<StockVal>, String> {
// Connect to database.
let mut client = db_connect(state, DB_USER, DB_PASS)?;
// Query database for table.
let mut stocks: Vec<StockVal> = Vec::new();
match client.query(format!("SELECT * FROM asset_schema.{} WHERE time_since_epoch >= {} AND time_since_epoch <= {}", searched_symbol, first_time_epoch, second_time_epoch).as_str(), &[]) {
match client.query(format!("SELECT * FROM asset_schema.{} WHERE time_since_epoch >= {} AND time_since_epoch <= {}",
searched_symbol, first_time_epoch, second_time_epoch).as_str(), &[]) {
Ok(all_rows) => {
for row in all_rows {
let mut val: StockVal = StockVal::default();

View File

@ -2,7 +2,8 @@ use crate::db::config::{*};
use crate::ds::server::global_state::GlobalState;
use crate::ds::generic::company::Company;
pub fn db_connect(state: &mut GlobalState, user: &'static str, pass: &'static str) -> Result<postgres::Client, String> {
pub fn db_connect(state: &mut GlobalState, user: &'static str,
pass: &'static str) -> Result<postgres::Client, String> {
/* Generate the requested string */
state.db_connect_str = format!("host={} port={} dbname={} user={} password={}",
DB_HOST, DB_HOST_PORT, DB_NAME, user, pass);

View File

@ -12,6 +12,7 @@ pub struct Account {
impl std::fmt::Display for Account {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({}, {}, {}, {}, {}, {:#?})", self.username, self.email, self.is_pass, self.pass_hash, self.portfolio, self.transactions)
write!(f, "({}, {}, {}, {}, {}, {:#?})", self.username, self.email, self.is_pass, self.pass_hash,
self.portfolio, self.transactions)
}
}

View File

@ -11,6 +11,7 @@ pub struct Order {
}
impl std::fmt::Display for Order {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({}, {}, {}, {}, {}, {}, {})", self.action_type, self.stock_symbol, self.stock_price, self.stock_amount, self.stock_amount, self.stock_filled, self.is_filled)
write!(f, "({}, {}, {}, {}, {}, {}, {})", self.action_type, self.stock_symbol, self.stock_price,
self.stock_amount, self.stock_amount, self.stock_filled, self.is_filled)
}
}

View File

@ -24,6 +24,8 @@ pub struct Position {
}
impl std::fmt::Display for Position {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {})", self.action_type, self.stock_symbol, self.stock_open_amount, self.stock_open_price, self.stock_open_cost, self.stock_close_amount, self.stock_close_price, self.stock_close_cost, self.open_epoch, self.close_epoch, self.is_open)
write!(f, "({}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {})", self.action_type, self.stock_symbol,
self.stock_open_amount, self.stock_open_price, self.stock_open_cost, self.stock_close_amount,
self.stock_close_price, self.stock_close_cost, self.open_epoch, self.close_epoch, self.is_open)
}
}

View File

@ -12,6 +12,7 @@ pub struct Company {
}
impl std::fmt::Display for Company {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({}, {}, {}, {}, {}, {}, {}, {}, {})", self.id, self.symbol, self.isin, self.company_name, self.primary_exchange, self.sector, self.industry, self.primary_sic_code, self.employees)
write!(f, "({}, {}, {}, {}, {}, {}, {}, {}, {})", self.id, self.symbol, self.isin, self.company_name,
self.primary_exchange, self.sector, self.industry, self.primary_sic_code, self.employees)
}
}

View File

@ -11,6 +11,7 @@ pub struct StockVal {
}
impl std::fmt::Display for StockVal {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({}, {}, {}, {}, {}, {})", self.id, self.isin, self.time_since_epoch, self.ask_price, self.bid_price, self.volume)
write!(f, "({}, {}, {}, {}, {}, {})", self.id, self.isin, self.time_since_epoch, self.ask_price,
self.bid_price, self.volume)
}
}

View File

@ -12,6 +12,7 @@ pub struct Message {
}
impl std::fmt::Display for Message {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({}, {}, {}, {}, {}, {}, {:#?})", self.message_type, self.instruction, self.data_size, self.argument_count, self.data_message_number, self.data_message_max, self.data)
write!(f, "({}, {}, {}, {}, {}, {}, {:#?})", self.message_type, self.instruction, self.data_size,
self.argument_count, self.data_message_number, self.data_message_max, self.data)
}
}