Skip to content
This repository has been archived by the owner on Feb 23, 2020. It is now read-only.

Commit

Permalink
Fix stats json
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Kuche <[email protected]>
  • Loading branch information
Zitrone44 committed Apr 1, 2018
1 parent 8d6f5e9 commit 3f1aab1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zlnk"
version = "0.4.0"
version = "0.4.1"
authors = ["Jonas Kuche <[email protected]>"]

[dependencies]
Expand Down
26 changes: 12 additions & 14 deletions src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use woothee::parser::Parser;
use env_loader::Env;
use geo_locate_ip::GeoLocateIP;
use serde_json::Value;
use std::collections::HashMap;

pub struct Stats {
pub refer: String,
Expand Down Expand Up @@ -118,30 +119,27 @@ impl Stats {
let _exists: String = connection.get(format!("short_{}", &short))?;
let stats_key = &format!("stats_{}", short);
let mut clicks: u64 = 0;
let mut refers: Vec<Value> = Vec::new();
let mut browsers: Vec<Value> = Vec::new();
let mut oss: Vec<Value> = Vec::new();
let mut countries: Vec<Value> = Vec::new();
let mut refers: HashMap<String, u64> = HashMap::new();
let mut browsers: HashMap<String, u64> = HashMap::new();
let mut oss: HashMap<String, u64> = HashMap::new();
let mut countries: HashMap<String, u64> = HashMap::new();
let keys: Vec<String> = connection.hkeys(stats_key)?;
for key in keys.iter() {
let value = connection.hget(stats_key, key)?;
let value :u64 = connection.hget(stats_key, key)?;
if key == "clicks" {
clicks = value;
} else {
let split: Vec<&str> = key.split('_').collect();
let split: Vec<_> = key.split('_').collect();
let typ = split[0];
let name = split[1];
let val = json!({
name: value
});
let name = split[1].to_string();
if typ == "refer" {
refers.push(val);
refers.insert(name, value);
} else if typ == "browser" {
browsers.push(val);
browsers.insert(name, value);
} else if typ == "os" {
oss.push(val);
oss.insert(name, value);
} else if typ == "country" {
countries.push(val);
countries.insert(name, value);
} else {
panic!("Invalid typ: {}!", typ);
}
Expand Down

0 comments on commit 3f1aab1

Please sign in to comment.