Skip to content

Commit

Permalink
fix: rendering of columns in convert (#110)
Browse files Browse the repository at this point in the history
Fix #94
  • Loading branch information
delehef authored Apr 10, 2024
1 parent d7f7be0 commit ea0dcff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
18 changes: 10 additions & 8 deletions src/exporters/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
column::ValueBacking,
compiler::{ColumnRef, ConstraintSet, Kind},
pretty::{Base, Pretty},
structs::Handle,
};
use anyhow::*;
use itertools::Itertools;
Expand Down Expand Up @@ -33,25 +34,26 @@ pub(crate) fn to_csv(cs: &ConstraintSet, exclude: &[String], filename: &str) ->
let mut file = BufWriter::new(File::create(&filename)?);

info!("Exporting {}", module);
let column_names = cs
let (column_refs, column_names): (Vec<ColumnRef>, Vec<Handle>) = cs
.columns
.iter_module(&module)
.map(|c| cs.handle(&c.0))
.sorted()
.collect::<Vec<_>>();
.map(|c| (c.0.clone(), cs.handle(&c.0).clone()))
.sorted_by(|x, y| x.1.cmp(&y.1))
.unzip();

file.write(column_names.iter().map(|h| &h.name).join(",").as_bytes())?;
file.write(&[b'\n'])?;
let max_i = cs.iter_len(&module);
dbg!(&module, cs.iter_len(&module));
for i in 0..max_i {
file.write(
cs.columns
.iter_module(&module)
column_refs
.iter()
.map(|col| {
cs.columns
.get(&col.0, i.try_into().unwrap(), false)
.get(&col, i.try_into().unwrap(), false)
.unwrap_or_default()
.pretty_with_base(col.1.base)
.pretty()
})
.join(",")
.as_bytes(),
Expand Down
8 changes: 2 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,12 +700,8 @@ fn main() -> Result<()> {
exclude,
} => {
let mut cs = builder.into_constraint_set()?;
if tracefile.ends_with("lt") {
import::parse_binary_trace(&tracefile, &mut cs, true)
} else {
import::parse_json_trace(&tracefile, &mut cs, true)
}
.with_context(|| format!("while computing from `{}`", tracefile))?;
compute::compute_trace(&tracefile, &mut cs, false)
.with_context(|| format!("while expanding `{}`", tracefile))?;

match format.as_str() {
"csv" => exporters::convert::to_csv(
Expand Down

0 comments on commit ea0dcff

Please sign in to comment.