Skip to content

Commit

Permalink
Update reader's version with new History columns names
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiAudoin committed Jul 26, 2023
1 parent b8db10f commit b7f9988
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
with:
files: target/x86_64-unknown-linux-musl/release/*
tag_name: v1.0.0
release_name: Release v1.0.0
release_name: Release v1.1.0
2 changes: 1 addition & 1 deletion src/history_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn process_history(
tag_list: HashSet<&str>,
) -> HashMap<i64, GatheredInfos> {
let mut elements_info: HashMap<i64, GatheredInfos> = HashMap::new();
//

let reader_result = ElementReader::from_path(history_file_path);

let reader = match reader_result {
Expand Down
8 changes: 4 additions & 4 deletions src/load_infos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ pub fn load(

for (key, value) in nodes_info.iter() {
let mut row: Vec<&(dyn ToSql + Sync)> = Vec::new();
let first_timestamp = value.timestamps.iter().min().unwrap();
let last_timestamp = value.timestamps.iter().max().unwrap();
let first_update = value.timestamps.iter().min().unwrap();
let last_update = value.timestamps.iter().max().unwrap();
let users_number = value.uids.iter().unique().count() as i64;
let versions_number = value.timestamps.len() as i64;
row.push(key);
row.push(&value.timestamps);
row.push(&value.changesets);
row.push(first_timestamp);
row.push(last_timestamp);
row.push(first_update);
row.push(last_update);
row.push(&users_number);
row.push(&versions_number);
writer.write(&row).unwrap();
Expand Down
21 changes: 15 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use std::collections::HashSet;
use std::env;
use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;
use std::time::Instant;

mod history_processing;
mod infos;
mod load_infos;
mod postgres_client;

use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;

const SCHEMA: &str = "OSM";
const TABLE: &str = "HISTORY";

Expand All @@ -34,12 +33,22 @@ fn main() {
}
}

// Read tag_list file and store tags into an Hashset (ignore values after the equal signs)
let file = File::open(tag_list_file_path).expect("Failed to open tag list file.");
let reader = io::BufReader::new(file);
let mut tag_list_string: Vec<String> = Vec::new();
for line in reader.lines() {
let line = line.unwrap_or("".parse().unwrap());
tag_list_string.push(line);
let final_line = match line {
Ok(line) => {
if let Some(index) = line.find('=') {
line[..index].to_owned()
} else {
line.to_owned()
}
}
Err(_) => String::new(),
};
tag_list_string.push(final_line);
}
let tag_list: HashSet<&str> = tag_list_string.iter().map(|s| s.as_str()).collect();

Expand Down
4 changes: 2 additions & 2 deletions src/postgres_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub fn create_table_history(client: &mut Client, schema: &str, table: &str) {
id int8,
timestamps TIMESTAMP WITH TIME ZONE[],
changesets int8[],
first_timestamps TIMESTAMP WITH TIME ZONE,
last_timestamps TIMESTAMP WITH TIME ZONE,
first_update TIMESTAMP WITH TIME ZONE,
last_update TIMESTAMP WITH TIME ZONE,
users_number int8,
versions_number int8)",
schema, table
Expand Down

0 comments on commit b7f9988

Please sign in to comment.