Skip to content

Commit

Permalink
Update human format to include year cost estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-mdr committed Feb 9, 2023
1 parent bdd00a1 commit 838770e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
36 changes: 22 additions & 14 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,33 @@ Here are few examples with different output formats. Note that `json` format wil
osc-cost --format=human # default
Summary:
╭───────────────────────┬──────────────╮
Account Id865343815873
Account Id 620346218618
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
Total price per hour ┆ 0.27983564$
│ Total price per hour ┆ 2.2062643€
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ Total price per month ┆ 204.28001$ │
│ Total price per month ┆ 1610.5729€ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ Total price per year ┆ 19326.875€ │
╰───────────────────────┴──────────────╯
Details:
╭───────────────┬───────┬──────────────────────┬───────────────────────╮
│ Resource Type ┆ Count ┆ Total price per hour ┆ Total price per month │
╞═══════════════╪═══════╪══════════════════════╪═══════════════════════╡
│ Volume ┆ 1 ┆ 0.015068493$ ┆ 11$ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ PublicIp ┆ 3 ┆ 0.01$ ┆ 7.2999997$ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ Snapshot ┆ 46 ┆ 0.05876714$ ┆ 42.900017$ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ Vm ┆ 1 ┆ 0.19600001$ ┆ 143.08$ │
╰───────────────┴───────┴──────────────────────┴───────────────────────╯
╭───────────────┬───────┬──────────────────────┬───────────────────────┬──────────────────────╮
│ Resource Type ┆ Count ┆ Total price per hour ┆ Total price per month ┆ Total price per year │
╞═══════════════╪═══════╪══════════════════════╪═══════════════════════╪══════════════════════╡
│ Snapshot ┆ 23 ┆ 0.03164384€ ┆ 23.1€ ┆ 277.2€ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ Vm ┆ 9 ┆ 1.7939999€ ┆ 1309.6199€ ┆ 15715.438€ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ LoadBalancer ┆ 2 ┆ 0.06€ ┆ 43.8€ ┆ 525.6€ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ NatServices ┆ 2 ┆ 0.1€ ┆ 73€ ┆ 876€ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ Volume ┆ 12 ┆ 0.20554796€ ┆ 150.04999€ ┆ 1800.5999€ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ PublicIp ┆ 7 ┆ 0.015€ ┆ 10.95€ ┆ 131.4€ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ Oos ┆ 5 ┆ 0.00007237231€ ┆ 0.05283179€ ┆ 0.63398147€ │
╰───────────────┴───────┴──────────────────────┴───────────────────────┴──────────────────────╯
```
```
Expand Down
16 changes: 14 additions & 2 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,13 @@ impl Resources {
.load_preset(UTF8_FULL)
.apply_modifier(UTF8_ROUND_CORNERS)
.set_content_arrangement(ContentArrangement::Dynamic)
.set_width(80)
.set_width(100)
.set_header(vec![
"Resource Type",
"Count",
"Total price per hour",
"Total price per month",
"Total price per year",
]);

for resource in self.resources.iter() {
Expand Down Expand Up @@ -236,6 +237,13 @@ impl Resources {
.ok_or("could not get the price_per_month")?,
currency
),
format!(
"{}{}",
agg.price_per_month
.ok_or("could not get the price_per_year")?
* 12.0,
currency
),
])
}
_ => {
Expand All @@ -249,7 +257,7 @@ impl Resources {
.load_preset(UTF8_FULL)
.apply_modifier(UTF8_ROUND_CORNERS)
.set_content_arrangement(ContentArrangement::Dynamic)
.set_width(80)
.set_width(100)
.add_row(vec![Cell::new("Account Id"), Cell::new(account_id)])
.add_row(vec![
Cell::new("Total price per hour"),
Expand All @@ -258,6 +266,10 @@ impl Resources {
.add_row(vec![
Cell::new("Total price per month"),
Cell::new(format!("{}{}", self.cost_per_month()?, currency)),
])
.add_row(vec![
Cell::new("Total price per year"),
Cell::new(format!("{}{}", self.cost_per_year()?, currency)),
]);

Ok(format!("Summary:\n{table}\n\nDetails:\n{table_resource}"))
Expand Down

0 comments on commit 838770e

Please sign in to comment.