Commit 45ca8a95 authored by Pascal Engélibert's avatar Pascal Engélibert 🚴
Browse files

Convert subcommand

parent 21e1867d
......@@ -101,7 +101,7 @@ pub struct IndexedProbaList<I, T> {
pub val: ProbaList<T>,
}
#[derive(Debug, Serialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct TxResult {
pub mean: Proba,
pub std_dev: Proba,
......@@ -116,7 +116,7 @@ pub enum PathResult {
Internal(Vec<PathResult>),
}
#[derive(Debug, Serialize, StructOpt)]
#[derive(Debug, Deserialize, Serialize, StructOpt)]
pub struct Settings {
/// List of possible amounts with probas
#[structopt(default_value="{\"next\":0,\"val\":[{\"event\":100,\"proba\":1.0}]}", long="amounts", parse(try_from_str=serde_json::from_str), short="a")]
......@@ -188,7 +188,7 @@ impl FromStr for ExportFormat {
}
}
#[derive(Serialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct ExportResults {
pub expired: Vec<usize>,
pub results: Vec<(BlockId, TxResult)>,
......
use crate::cli;
use crate::common::*;
use bincode;
use serde_cbor;
use serde_json;
use std::io::{Read, Write};
pub fn run_convert(opt: cli::ConvertSubcommand) {
let stdin = std::io::stdin();
let mut handle = stdin.lock();
let mut raw = Vec::new();
handle.read_to_end(&mut raw).unwrap();
let export_results: ExportResults = match opt.input_format {
ExportFormat::Bincode => bincode::deserialize(&raw).unwrap(),
ExportFormat::Cbor => serde_cbor::from_slice(&raw).unwrap(),
ExportFormat::Json => serde_json::from_str(&std::str::from_utf8(&raw).unwrap()).unwrap(),
};
let stdout = std::io::stdout();
let mut handle = stdout.lock();
handle
.write(&match opt.output_format {
ExportFormat::Bincode => bincode::serialize(&export_results).unwrap(),
ExportFormat::Cbor => serde_cbor::to_vec(&export_results).unwrap(),
ExportFormat::Json => serde_json::to_string(&export_results).unwrap().into_bytes(),
})
.unwrap();
}
mod client;
mod common;
mod convert;
mod local;
mod server;
mod utils;
......@@ -20,6 +21,7 @@ fn main() {
match opt.cmd {
cli::MainSubcommand::Client(cmd) => client::run_client(cmd),
cli::MainSubcommand::Convert(cmd) => convert::run_convert(cmd),
cli::MainSubcommand::Local(cmd) => local::run_local(cmd),
cli::MainSubcommand::Server(cmd) => server::run_server(cmd),
}
......
......@@ -5,6 +5,15 @@ use structopt::StructOpt;
#[derive(Debug, StructOpt)]
pub struct ClientSubcommand {}
#[derive(Debug, StructOpt)]
pub struct ConvertSubcommand {
#[structopt(short = "i")]
pub input_format: ExportFormat,
#[structopt(short = "o")]
pub output_format: ExportFormat,
}
#[derive(Debug, StructOpt)]
pub struct LocalSubcommand {
/// Export format
......@@ -29,6 +38,7 @@ pub struct ServerSubcommand {}
#[derive(Debug, StructOpt)]
pub enum MainSubcommand {
Client(ClientSubcommand),
Convert(ConvertSubcommand),
Local(LocalSubcommand),
Server(ServerSubcommand),
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
import json
f=open("test.json","r")
a=json.load(f)
f.close()
f=open("test.csv","w")
for i in a["results"]:
f.write("{},{},{},{},{}\n".format(i[0],i[1]["mean"],i[1]["std_dev"],i[1]["min"],i[1]["max"]))
f.close()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment