Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d87b4b5

Browse files
fix float bug in resp
1 parent 706a89d commit d87b4b5

File tree

10 files changed

+50
-38
lines changed

10 files changed

+50
-38
lines changed

‎CHANGELOG.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
## v0.2.5
1+
## v0.2.7
2+
fixed float bug in result
3+
4+
## v0.2.6
25
sync config while change current lang
36

47
## v0.2.5

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ path = "src/bin/lc.rs"
44

55
[package]
66
name = "leetcode-cli"
7-
version = "0.2.6"
7+
version = "0.2.7"
88
authors = ["clearloop <udtrokia@163.com>"]
99
edition = "2018"
1010
description = "Leet your code in command-line."

‎README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cargo install leetcode-cli
2323
**Please make sure you have logined in `leetcode.com` with `chrome`**, more info plz checkout [this](#cookies)
2424

2525
```sh
26-
leetcode 0.2.6
26+
leetcode 0.2.7
2727
clearloop <udtrokia@163.com>
2828
Here's to the crazy ones 👻
2929
@@ -88,6 +88,7 @@ leetcode edit 1
8888
```
8989
9090
```rust
91+
# struct Solution;
9192
impl Solution {
9293
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
9394
use std::collections::HashMap;
@@ -128,7 +129,7 @@ leetcode test 1
128129
leetcode submit 1
129130
```
130131
131-
```
132+
```sh
132133
133134
Success
134135

‎src/cache/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ impl Cache {
179179
run: Run,
180180
rfid: i32,
181181
) -> Result<(HashMap<&'static str, String>, [String; 2]), Error> {
182+
trace!("pre run code...");
182183
use crate::helper::code_path;
183184
use std::fs::File;
184185
use std::io::Read;

‎src/cache/models.rs‎

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,23 @@ impl std::fmt::Display for VerifyResult {
263263
eca,
264264
)
265265
} else if !self.submit.compare_result.is_empty() {
266+
let (mut rp, mut mp) = (0, 0);
267+
if let Some(n) = &self.analyse.runtime_percentile {
268+
if n.is_f64() {
269+
rp = n.as_f64().unwrap_or(0.0) as i64;
270+
} else {
271+
rp = n.as_i64().unwrap_or(0);
272+
}
273+
}
274+
275+
if let Some(n) = &self.analyse.memory_percentile {
276+
if n.is_f64() {
277+
mp = n.as_f64().unwrap_or(0.0) as i64;
278+
} else {
279+
mp = n.as_i64().unwrap_or(0);
280+
}
281+
}
282+
266283
// Submit Successfully
267284
write!(
268285
f,
@@ -271,12 +288,7 @@ impl std::fmt::Display for VerifyResult {
271288
" Runtime: ".dimmed(),
272289
&self.status.status_runtime.bold(),
273290
", faster than ",
274-
&self
275-
.analyse
276-
.runtime_percentile
277-
.unwrap_or(0)
278-
.to_string()
279-
.bold(),
291+
rp.to_string().bold(),
280292
"% ".bold(),
281293
"of ",
282294
&self.pretty_lang,
@@ -286,12 +298,7 @@ impl std::fmt::Display for VerifyResult {
286298
" Memory Usage: ".dimmed(),
287299
&self.status.status_memory.bold(),
288300
", less than ",
289-
&self
290-
.analyse
291-
.memory_percentile
292-
.unwrap_or(0)
293-
.to_string()
294-
.bold(),
301+
mp.to_string().bold(),
295302
"% ".bold(),
296303
"of ",
297304
&self.pretty_lang,
@@ -338,6 +345,7 @@ use verify::*;
338345
mod verify {
339346
use super::super::parser::ssr;
340347
use serde::Deserialize;
348+
use serde_json::Number;
341349

342350
#[derive(Debug, Default, Deserialize)]
343351
pub struct Submit {
@@ -362,13 +370,13 @@ mod verify {
362370
#[derive(Debug, Default, Deserialize)]
363371
pub struct Analyse {
364372
#[serde(default)]
365-
pub total_correct: Option<i32>,
373+
pub total_correct: Option<Number>,
366374
#[serde(default)]
367-
pub total_testcases: Option<i32>,
375+
pub total_testcases: Option<Number>,
368376
#[serde(default)]
369-
pub runtime_percentile: Option<i32>,
377+
pub runtime_percentile: Option<Number>,
370378
#[serde(default)]
371-
pub memory_percentile: Option<i32>,
379+
pub memory_percentile: Option<Number>,
372380
}
373381

374382
#[derive(Debug, Default, Deserialize)]

‎src/cli.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use clap::{App, AppSettings};
1313
pub fn main() -> Result<(), Error> {
1414
let m = App::new("leetcode")
1515
.author("clearloop <udtrokia@163.com>")
16-
.version("0.2.6")
16+
.version("0.2.7")
1717
.about("Here's to the crazy ones 👻")
1818
.subcommands(vec![
1919
DataCommand::usage().display_order(1),

‎src/err.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl std::convert::From<diesel::result::Error> for Error {
6969
// serde
7070
impl std::convert::From<serde_json::error::Error> for Error {
7171
fn from(err: serde_json::Error) -> Self {
72+
error!("{:?}", &err);
7273
Error::ParseError(err.description().to_string())
7374
}
7475
}

‎src/lib.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//! **Please make sure you have logined in `leetcode.com` with `chrome`**, more info plz checkout [this](#cookies)
2424
//!
2525
//! ```sh
26-
//! leetcode 0.2.6
26+
//! leetcode 0.2.7
2727
//! clearloop <udtrokia@163.com>
2828
//! Here's to the crazy ones 👻
2929
//!
@@ -88,6 +88,7 @@
8888
//! ```
8989
//!
9090
//! ```rust
91+
//! # struct Solution;
9192
//! impl Solution {
9293
//! pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
9394
//! use std::collections::HashMap;
@@ -128,7 +129,7 @@
128129
//! leetcode submit 1
129130
//! ```
130131
//!
131-
//! ```
132+
//! ```sh
132133
//!
133134
//! Success
134135
//!

‎tests/de.rs‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// #[macro_use]
2-
// extern crate log;
1+
#[macro_use]
2+
extern crate log;
33
use leetcode_cli::cache::models::VerifyResult;
44
use serde_json;
55

@@ -26,3 +26,13 @@ fn de_from_test_success() {
2626
);
2727
assert!(r.is_ok());
2828
}
29+
30+
#[test]
31+
fn de_from_float_pencentile() {
32+
env_logger::init();
33+
let r: Result<VerifyResult, serde_json::Error> = serde_json::from_str(
34+
r#"{"status_code": 10, "lang": "rust", "run_success": true, "status_runtime": "4 ms", "memory": 2716000, "question_id": "203", "elapsed_time": 0, "compare_result": "11111111111111111111111111111111111111111111111111111111111111111", "code_output": "", "std_output": "", "last_testcase": "", "task_finish_time": 1578590021187, "total_correct": 65, "total_testcases": 65, "runtime_percentile": 76.9231, "status_memory": "2.7 MB", "memory_percentile": 100, "pretty_lang": "Rust", "submission_id": "292701790", "status_msg": "Accepted", "state": "SUCCESS"}"#,
35+
);
36+
debug!("{:?}", &r);
37+
assert!(r.is_ok());
38+
}

‎tests/tag.rs‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /