Skip to content

Commit fe0c911

Browse files
committed
switch to use Arc<ReportOptions>
1 parent ae5b958 commit fe0c911

File tree

8 files changed

+173
-248
lines changed

8 files changed

+173
-248
lines changed

src/column.rs

+9-33
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::intersection::Intersections;
22
use crate::py::{CompiledPython, PyReportOptions};
33
use crate::report_options::ReportOptions;
4-
4+
use std::sync::Arc;
55
#[derive(Debug, PartialEq)]
66
pub enum Value {
77
Int(i32),
@@ -67,7 +67,7 @@ pub trait ColumnReporter {
6767
fn value(
6868
&self,
6969
r: &Intersections,
70-
report_options: Option<&ReportOptions>,
70+
report_options: Arc<ReportOptions>,
7171
) -> Result<Value, ColumnError>;
7272
}
7373

@@ -185,28 +185,15 @@ impl ColumnReporter for Column<'_> {
185185
fn value(
186186
&self,
187187
r: &Intersections,
188-
report_options: Option<&ReportOptions>,
188+
report_options: Arc<ReportOptions>,
189189
) -> Result<Value, ColumnError> {
190190
match &self.value_parser {
191191
Some(ValueParser::Count(false)) => {
192192
// Return the count of overlapping intervals
193193
Ok(Value::Int(r.overlapping.len() as i32))
194194
}
195195
Some(ValueParser::Count(true)) => {
196-
// Return the count of overlapping intervals
197-
// BARF: TODO: this sucks.
198-
let report = r.report(
199-
&report_options.map(|o| &o.a_mode).unwrap_or_default(),
200-
&report_options.map(|o| &o.b_mode).unwrap_or_default(),
201-
&report_options.map(|o| &o.a_part).unwrap_or_default(),
202-
&report_options.map(|o| &o.b_part).unwrap_or_default(),
203-
&report_options
204-
.map(|o| &o.a_requirements)
205-
.unwrap_or_default(),
206-
&report_options
207-
.map(|o| &o.b_requirements)
208-
.unwrap_or_default(),
209-
);
196+
let report = r.report(report_options.clone());
210197
Ok(Value::Int(report.len() as i32))
211198
}
212199
Some(ValueParser::Sum) => {
@@ -218,18 +205,8 @@ impl ColumnReporter for Column<'_> {
218205
Some(ValueParser::Bases) => {
219206
// Calculate total number of bases covered by overlapping intervals
220207
// Use the report functionality to get the base count
221-
let default_mode = crate::report_options::IntersectionMode::default();
222-
let whole_part = crate::report_options::IntersectionPart::Whole;
223-
let base_requirement = crate::report_options::OverlapAmount::Bases(1);
224-
225-
let report = r.report(
226-
&default_mode,
227-
&default_mode,
228-
&whole_part,
229-
&whole_part,
230-
&base_requirement,
231-
&base_requirement,
232-
);
208+
209+
let report = r.report(report_options.clone());
233210

234211
let bases = report.count_bases_by_id();
235212
let total_bases: i32 = bases.iter().sum::<u64>() as i32;
@@ -259,10 +236,9 @@ impl ColumnReporter for Column<'_> {
259236
// For Python expressions, we should use the compiled Python object
260237
if let Some(py) = &self.py {
261238
// Convert intersection to PyIntersections and evaluate
262-
let py_intersection = crate::py::PyIntersections::from(r.clone());
263-
let py_report_options =
264-
report_options.map(|ro| PyReportOptions::new(ro.clone()));
265-
match py.eval(py_intersection, py_report_options) {
239+
let py_intersection =
240+
crate::py::PyIntersections::new(r.clone(), report_options.clone());
241+
match py.eval(py_intersection) {
266242
Ok(result) => Ok(Value::String(result)),
267243
Err(e) => Err(ColumnError::PythonError(format!(
268244
"Python error when evaluating expression: \"{}\": {}",

0 commit comments

Comments
 (0)