mirror of https://github.com/01-edu/public.git
Augusto
4 years ago
1 changed files with 58 additions and 0 deletions
@ -0,0 +1,58 @@ |
|||||||
|
## commit_stats |
||||||
|
|
||||||
|
### Instructions: |
||||||
|
|
||||||
|
In this exercise you will be provided with a json file `commits.json` with data corresponding to git commits in GitHub (extracted using the GitHub rest API), your job is to extract the relevant data and place it in a struct called `CommitData` to get the following information: |
||||||
|
|
||||||
|
1. Number of commits per author (identified by the GitHub login). |
||||||
|
|
||||||
|
2. The number of commits per author. |
||||||
|
|
||||||
|
Create two functions: |
||||||
|
|
||||||
|
- `commits_per_author`: which returns a hash map with the number of commits per author. |
||||||
|
|
||||||
|
- `commits_per_date`: which returns a hash map with the number of commits per week. |
||||||
|
|
||||||
|
- Note: A week is represented by the a year followed by the number of the |
||||||
|
week for example January 1, 2020 is in week 1 of 2020 an will be |
||||||
|
represented by a String with the form "2020-W1". |
||||||
|
|
||||||
|
### Notions: |
||||||
|
|
||||||
|
- [chrono](https://docs.rs/chrono/0.4.19/chrono) |
||||||
|
- [json](https://docs.rs/json/0.12.4/json/index.html) |
||||||
|
|
||||||
|
### Expected functions |
||||||
|
|
||||||
|
```rust |
||||||
|
pub fn commits_per_week(data: &json::JsonValue) -> HashMap<String, u32> { |
||||||
|
} |
||||||
|
|
||||||
|
pub fn commits_per_author(data: &json::JsonValue) -> HashMap<String, u32> { |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible test for your function: |
||||||
|
|
||||||
|
```rust |
||||||
|
use commit_stats::{commits_per_week, commits_per_author}; |
||||||
|
|
||||||
|
fn main() { |
||||||
|
let contents = fs::read_to_string("commits.json").unwrap(); |
||||||
|
let serialized = json::parse(&contents).unwrap(); |
||||||
|
println!("{:?}", commits_per_week(&serialized)); |
||||||
|
println!("{:?}", commits_per_author(&serialized)); |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output: |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/[[ROOT]]/test$ cargo run |
||||||
|
{"2020-W44": 5, "2020-W36": 1, "2020-W31": 1, ... ,"2020-W45": 4, "2020-W46": 4} |
||||||
|
{"homembaixinho": 2, "mwenzkowski": 3, ... ,"tamirzb": 1, "paul-ri": 2, "RPigott": 1} |
||||||
|
student@ubuntu:~/[[ROOT]]/test$ |
||||||
|
``` |
Loading…
Reference in new issue