This commit is contained in:
Elijah McMorris 2023-06-30 00:57:27 +00:00
parent 41bd1e8fe7
commit ffb24e7943
Signed by: NexVeridian
SSH key fingerprint: SHA256:bsA1SKZxuEcEVHAy3gY1HUeM5ykRJl0U0kQHQn0hMg8
6 changed files with 93 additions and 81 deletions

View file

@ -17,12 +17,13 @@ polars = { version = "0.30", features = [
reqwest = { version = "0.11", features = ["blocking"] } reqwest = { version = "0.11", features = ["blocking"] }
glob = { version = "0.3" } glob = { version = "0.3" }
clokwerk = "0.4.0" clokwerk = "0.4.0"
strum_macros = "0.24" strum_macros = "0.25"
strum = "0.24" strum = "0.25"
tokio = { version = "1.26", features = ["full"] } tokio = { version = "1.26", features = ["full"] }
openssl = { version = "0.10", features = ["vendored"] } openssl = { version = "0.10", features = ["vendored"] }
chrono = { version = "0.4", features = ["serde"] } chrono = { version = "0.4", features = ["serde"] }
serde_json = "1.0" serde_json = "1.0"
rand = "0.8"
[dev-dependencies] [dev-dependencies]
serial_test = "*" serial_test = "*"

View file

@ -1,15 +1,29 @@
FROM rust:latest AS builder FROM rust:bookworm AS builder
RUN rustup target add x86_64-unknown-linux-musl && apt update && apt install -y musl-tools musl-dev RUN apt-get update && \
apt install -y musl-tools musl-dev libssl-dev clang mold
# RUN curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
RUN curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C /usr/local/bin
# RUN cargo install cargo-nextest --locked
WORKDIR /ark-invest-api-rust-data WORKDIR /ark-invest-api-rust-data
COPY . . COPY . .
RUN rustup target add x86_64-unknown-linux-musl && rustup update && cargo update
RUN --mount=type=cache,target=/usr/local/cargo,from=rust,source=/usr/local/cargo \ RUN --mount=type=cache,target=/usr/local/cargo,from=rust,source=/usr/local/cargo \
--mount=type=cache,target=./target \ --mount=type=cache,target=./target \
cargo build --target x86_64-unknown-linux-musl --release && \ cargo build --target x86_64-unknown-linux-musl --release && \
cp ./target/x86_64-unknown-linux-musl/release/ark-invest-api-rust-data . cp ./target/target/x86_64-unknown-linux-musl/release/ark-invest-api-rust-data .
FROM builder AS test
RUN --mount=type=cache,target=/usr/local/cargo,from=rust,source=/usr/local/cargo \
--mount=type=cache,target=./target \
cargo nextest run --release --target x86_64-unknown-linux-musl \
-E "all() - test(get_api) - kind(bin)"
FROM alpine:latest FROM alpine:latest

View file

@ -3,15 +3,15 @@ services:
ark-invest-api-rust-data: ark-invest-api-rust-data:
# image: ghcr.io/NexVeridian/ark-invest-api-rust-data:latest # image: ghcr.io/NexVeridian/ark-invest-api-rust-data:latest
image: ark-invest-api-rust-data image: ark-invest-api-rust-data
container_name: ark-invest-api-rust-data
build: build:
context: . context: .
target: test
args: args:
DOCKER_BUILDKIT: 1 DOCKER_BUILDKIT: 1
container_name: ark-invest-api-rust-data
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- ./data:/ark-invest-api-rust-data/data - ./data:/ark-invest-api-rust-data/data
volumes: volumes:
data: data:
Data:

View file

@ -1,70 +1,63 @@
// use clokwerk::{AsyncScheduler, Job, TimeUnits}; use clokwerk::{AsyncScheduler, Job, TimeUnits};
// use polars::prelude::LazyFrame; // use polars::prelude::LazyFrame;
// use polars::prelude::*; // use polars::prelude::*;
// use std::error::Error; use rand::Rng;
// use std::result::Result; use std::error::Error;
// use std::time::Duration; use std::result::Result;
// use strum::IntoEnumIterator; use std::time::Duration;
use strum::IntoEnumIterator;
mod util; mod util;
use util::*; use util::*;
// #[tokio::main] #[tokio::main]
// async fn main() { async fn main() {
// let mut scheduler = AsyncScheduler::new(); let mut scheduler = AsyncScheduler::new();
// scheduler.every(1.day()).at("11:30 pm").run(|| async { println!("Scheduler Started");
// for x in Ticker::iter() { scheduler.every(1.day()).at("11:30 pm").run(|| async {
// let plan = || -> Result<(), Box<dyn Error>> { for x in Ticker::iter() {
// let df = LazyFrame::scan_parquet( if x == Ticker::ARKVC {
// format!("data/old/{}/part.0.parquet", x), continue;
// ScanArgsParquet::default(), }
// )?; let plan = || -> Result<(), Box<dyn Error>> {
// let df = df_format(x, df)?; let df = Ark::new(Source::Ark, x, None)?
// write_parquet(x, df)?; .format()?
// Ok(()) .write_parquet()?
// }; .collect()?;
// if plan().is_ok() {} println!("{:#?}", df.head(Some(1)));
// } Ok(())
// }); };
// let dfn = read_parquet(Ticker::ARKF).unwrap().collect().unwrap(); if plan().is_ok() {}
// println!("{:#?}", dfn); let sec = rand::thread_rng().gen_range(10..=30);
// loop { tokio::time::sleep(Duration::from_secs(sec)).await;
// scheduler.run_pending().await; }
// // tokio::time::sleep(Duration::from_millis(10)).await; });
// tokio::time::sleep(Duration::from_secs(1)).await;
// }
// }
fn main() -> Result<(), Box<dyn std::error::Error>> { loop {
// let csv = Ark::merge_old_csv_to_parquet(Ticker::ARKK, None) scheduler.run_pending().await;
// .unwrap() // tokio::time::sleep(Duration::from_millis(10)).await;
// .format() tokio::time::sleep(Duration::from_secs(1)).await;
// .unwrap() }
// .write_parquet()
// .unwrap()
// .collect()
// .unwrap();
// println!("{:#?}", csv);
let read = Ark::new(Source::Read, Ticker::ARKK, None)?.collect()?;
println!("{:#?}", read.dtypes());
println!("{:#?}", read.get_column_names());
println!("{:#?}", read);
// let api = Ark::new(Source::ApiFull, Ticker::ARKK, None)
// .unwrap()
// .collect()
// .unwrap();
// println!("{:#?}", api);
// let ark = Ark::new(Source::Ark, Ticker::ARKK, None)?.collect()?;
// println!("{:#?}", ark);
// let ark = Ark::new(Source::Ark, Ticker::ARKVC, None)
// .unwrap()
// .collect()
// .unwrap();
// println!("{:#?}", ark);
Ok(())
} }
// fn main() -> Result<(), Box<dyn std::error::Error>> {
// let csv = Ark::merge_old_csv_to_parquet(Ticker::ARKK, None)?
// .format()?
// .write_parquet()?
// .collect()?;
// println!("{:#?}", csv);
// let read = Ark::new(Source::Read, Ticker::ARKK, None)?.collect()?;
// println!("{:#?}", read.dtypes());
// println!("{:#?}", read.get_column_names());
// println!("{:#?}", read);
// let api = Ark::new(Source::ApiFull, Ticker::ARKK, None)?.collect()?;
// println!("{:#?}", api);
// let ark = Ark::new(Source::Ark, Ticker::ARKK, None)?.collect()?;
// println!("{:#?}", ark);
// let ark = Ark::new(Source::Ark, Ticker::ARKVC, None)?.collect()?;
// println!("{:#?}", ark);
// Ok(())
// }

View file

@ -12,7 +12,7 @@ use std::path::Path;
use std::result::Result; use std::result::Result;
use strum_macros::EnumIter; use strum_macros::EnumIter;
#[derive(strum_macros::Display, EnumIter, Clone, Copy)] #[derive(strum_macros::Display, EnumIter, Clone, Copy, PartialEq)]
pub enum Ticker { pub enum Ticker {
ARKVC, ARKVC,
ARKF, ARKF,

View file

@ -15,18 +15,22 @@ fn get_api_arkk() -> Result<(), Box<dyn Error>> {
.get_api(NaiveDate::from_ymd_opt(2023, 5, 18))? .get_api(NaiveDate::from_ymd_opt(2023, 5, 18))?
.collect()?; .collect()?;
assert_eq!( let expected = [
df.get_column_names(), "company",
[ "cusip",
"company", "date",
"cusip", "market_value",
"date", "share_price",
"market_value", "shares",
"share_price", "ticker",
"shares", "weight",
"ticker", "weight_rank",
"weight" ];
] let actual = df.get_column_names();
assert!(
actual == expected || actual == expected[..expected.len() - 1],
"Column names are wrong"
); );
Ok(()) Ok(())
} }