Skip to content

Commit

Permalink
Merge pull request #53 from lexara-prime-ai/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
irfanghat authored Jun 18, 2024
2 parents 19c22d0 + 9bfe5e9 commit d82a6e5
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.terraform
*.tfstate
.env
/**/.venv
service_account.json
garage.toml

Expand Down
15 changes: 15 additions & 0 deletions hyper/hyper/error_handling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Terminal colors.
CRED = "\033[91m"
CEND = "\033[0m"


class ErrorHandling:
def propagate_error(self, process_name: str, message: str):
print(
f"""
{CRED} An [ERROR] occured {CEND}
Info: {message}
Process: {process_name}
"""
)
23 changes: 19 additions & 4 deletions hyper/hyper/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import constants
import drive
import error_handling

import python_wrapper.python_wrapper

Expand All @@ -14,17 +15,31 @@ def __init__(self, interval, num_rows):
self.write_path = os.path.join(constants.FILE_PATH, constants.FILE_NAME)
self.interval = interval
self.num_rows = num_rows
self.error_handling = error_handling.ErrorHandling()

# ---------------------------------------------------
"""Fetch data from WSPR database via <wspr_cdk>."""
# ---------------------------------------------------
async def fetch_data(self):
try:
output = await python_wrapper.python_wrapper.get_wspr_spots(
self.num_rows, "JSON"
)
return output
except Exception as e:
self.error_handling.propagate_error("fetch_data", f"{e}")

# ----------------------------------------------
"""Write data to <csv> file asynchronously."""
# ----------------------------------------------
async def write_to_csv(self):
"""
Args: self.
return type: ()
"""

try:
output = await python_wrapper.python_wrapper.get_wspr_spots(
self.num_rows, "JSON"
)
output = await self.fetch_data()
data = output.get_data()

# Display data that's being fetched for [DEBUG] purposes.
Expand Down Expand Up @@ -94,7 +109,7 @@ async def write_to_csv(self):
# Upload [output] file to Google Drive.
drive.upload_to_drive(constants.FULL_PATH)
except Exception as e:
print("An [ERROR] occurred: ", e)
self.error_handling.propagate_error("write_to_csv", f"{e}")

async def display_data(self, data):
"""
Expand Down
2 changes: 2 additions & 0 deletions object_storage/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM rust:latest

36 changes: 28 additions & 8 deletions scripts/bash/python_deps.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
#!/bin/bash

# Terminal Colors.
NORMAL=$(tput sgr0)
UNDERLINE=$(tput smul)
RED=$(tput setaf 1)
BLUE=$(tput setaf 4)
GREEN=$(tput setaf 2)
# BLACK=$(tput setaf 0)
# YELLOW=$(tput setaf 3)
# LIME_YELLOW=$(tput setaf 190)
# POWDER_BLUE=$(tput setaf 153)
# MAGENTA=$(tput setaf 5)
# CYAN=$(tput setaf 6)
# WHITE=$(tput setaf 7)
# BRIGHT=$(tput bold)
# NORMAL=$(tput sgr0)
# REVERSE=$(tput smso)
# BLINK=$(tput blink)

# Install [patchelf]
sudo apt-get -y install patchelf -y

# Check if pip is installed.
if ! command -v pip &>/dev/null; then
echo "pip not found. Installing pip..."
echo "${BLUE}pip not found. Installing pip...${NORMAL}"
sudo apt-get install -y python3-pip
else
echo "pip is already installed."
echo "${GREEN}pip is already installed.${NORMAL}"
fi


# Modules that will be installed/upgraded.
modules=("modal" "mkdocs" "maturin" "patchelf" "tableauhyperapi" "google-api-python-client" "google-auth-httplib2" "google-auth-oauthlib")

echo "Installing dependencies: ${modules[*]}..."
echo "${BLUE}Installing dependencies: ${modules[*]}...${NORMAL}"
pip install "${modules[@]}" --upgrade

# Verify module installation.
verify_installation() {
local module=$1
local import_name=$2
echo "Verifying ${module} installation..."
printf "\nVERIFYING %s INSTALLATION...\n" "${module}"
if python3 -c "import ${import_name}" &>/dev/null; then
echo "${module} successfully installed."
printf "%s ${UNDERLINE}${GREEN}SUCCESSFULLY${NORMAL} INSTALLED.\n\n" "${module}"
else
echo "Failed to install ${module}."
echo "${UNDERLINE}${RED}FAILED${NORMAL} TO INSTALL ${module}."
fi
}

Expand All @@ -47,4 +67,4 @@ done
# The [modules] array contains the names of all the modules to be installed.
# The [dictionary] [module_import_map] maps module names to their respective import names.
# The verify_installation function takes a module name and its import name as arguments, checks if the module can be imported, and prints the appropriate message.
# The script iterates over the module_import_map dictionary to verify the installation of each module using the verify_installation function.
# The script iterates over the module_import_map dictionary to verify the installation of each module using the verify_installation function.
2 changes: 1 addition & 1 deletion src/services/prelude.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub use crate::services::*;
pub use crate::services::*;
2 changes: 1 addition & 1 deletion src/state/actions/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod db_actions;
pub mod db_actions;
17 changes: 15 additions & 2 deletions src/state/effects/db_effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,24 @@ impl ClickHouseClient {
ClickHouseAction::Get => {
println!("Fetching all records...");

let query = "select * from wspr.rx where time > subtractHours(now(), 2) limit";
/*
A <String> is a growable buffer. Its purpose is to be modifiable.
Why would you pass around a <String> if it's meant to be constant?
Remember that API should usually take a <&str> as argument, not a <String>.
The right constant type is <&str>. – Denys Séguret
Hence,
const QUERY: &str =
"select * from wspr.rx where time > subtractHours(now(), 12) limit";
*/

const QUERY: &str =
"select * from wspr.rx where time > subtractHours(now(), 12) limit";

// Create [SERVICE] request.
let result = data::DataService::GET_SPOT_DATA(
&query.to_string(),
&QUERY.to_string(),
limit.to_string(),
Some(result_format.to_string()),
)
Expand Down
2 changes: 1 addition & 1 deletion src/state/effects/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod db_effects;
pub mod db_effects;
4 changes: 2 additions & 2 deletions src/state/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod actions;
pub mod db_state;
pub mod effects;
pub mod models;
pub mod prelude;
pub mod reducers;
pub mod effects;
pub mod models;
2 changes: 1 addition & 1 deletion src/state/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod spot;
pub mod spot;
2 changes: 1 addition & 1 deletion src/state/reducers/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod db_reducers;
pub mod db_reducers;

0 comments on commit d82a6e5

Please sign in to comment.