Skip to content

Commit

Permalink
Add custom key/value to reports
Browse files Browse the repository at this point in the history
  • Loading branch information
ericpp committed Dec 12, 2024
1 parent 4bcf3ae commit 6d4b9e9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ pub async fn report_generate(
let mut csv = String::new();

//CSV column name header
let mut headers = "index,type,time,value_msat,value_sat,value_msat_total,value_sat_total,action,sender,app,message,podcast,episode,remote_podcast,remote_episode".to_string();
let mut headers = "index,type,time,value_msat,value_sat,value_msat_total,value_sat_total,action,sender,app,message,podcast,episode,remote_podcast,remote_episode,custom_key,custom_value".to_string();

if btc_prices.is_some() {
headers.push_str(",btc_close,value_usd,value_usd_total");
Expand Down Expand Up @@ -1147,7 +1147,7 @@ pub async fn report_generate(
//The main export data formatting
csv.push_str(
format!(
"{},{},\"{}\",{},{},{},{},{},\"{}\",\"{}\",\"{}\",\"{}\",\"{}\",\"{}\",\"{}\"",
"{},{},\"{}\",{},{},{},{},{},\"{}\",\"{}\",\"{}\",\"{}\",\"{}\",\"{}\",\"{}\",\"{}\",\"{}\"",
boost.index,
list,
boost_time,
Expand All @@ -1162,7 +1162,9 @@ pub async fn report_generate(
BoostRecord::escape_for_csv(boost.podcast),
BoostRecord::escape_for_csv(boost.episode),
BoostRecord::escape_for_csv(boost.remote_podcast.unwrap_or("".to_string())),
BoostRecord::escape_for_csv(boost.remote_episode.unwrap_or("".to_string()))
BoostRecord::escape_for_csv(boost.remote_episode.unwrap_or("".to_string())),
BoostRecord::escape_for_csv(boost.custom_key.map(|k| k.to_string()).unwrap_or_default()),
BoostRecord::escape_for_csv(boost.custom_value.unwrap_or("".to_string()))
).as_str()
);

Expand Down Expand Up @@ -1269,7 +1271,7 @@ pub async fn csv_export_boosts(
let mut csv = String::new();

//CSV column name header
csv.push_str("count,index,time,value_msat,value_sat,value_msat_total,value_sat_total,action,sender,app,message,podcast,episode,remote_podcast,remote_episode\n");
csv.push_str("count,index,time,value_msat,value_sat,value_msat_total,value_sat_total,action,sender,app,message,podcast,episode,remote_podcast,remote_episode,custom_key,custom_value\n");

//Iterate the boost set
let mut count: u64 = 1;
Expand All @@ -1291,7 +1293,7 @@ pub async fn csv_export_boosts(
//The main export data formatting
csv.push_str(
format!(
"{},{},\"{}\",{},{},{},{},{},\"{}\",\"{}\",\"{}\",\"{}\",\"{}\",\"{}\",\"{}\"\n",
"{},{},\"{}\",{},{},{},{},{},\"{}\",\"{}\",\"{}\",\"{}\",\"{}\",\"{}\",\"{}\",\"{}\",\"{}\"\n",
count,
boost.index,
boost_time,
Expand All @@ -1306,7 +1308,9 @@ pub async fn csv_export_boosts(
BoostRecord::escape_for_csv(boost.podcast),
BoostRecord::escape_for_csv(boost.episode),
BoostRecord::escape_for_csv(boost.remote_podcast.unwrap_or("".to_string())),
BoostRecord::escape_for_csv(boost.remote_episode.unwrap_or("".to_string()))
BoostRecord::escape_for_csv(boost.remote_episode.unwrap_or("".to_string())),
BoostRecord::escape_for_csv(boost.custom_key.map(|k| k.to_string()).unwrap_or_default()),
BoostRecord::escape_for_csv(boost.custom_value.unwrap_or("".to_string()))
).as_str()
);

Expand Down

0 comments on commit 6d4b9e9

Please sign in to comment.