Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions rust-code-analysis-web/src/web/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ mod tests {
"n1": 2.0,
"volume": 4.754_887_502_163_468},
"loc": {"cloc": 1.0, "ploc": 2.0, "lloc": 1.0, "sloc": 4.0, "blank": 1.0},
"nom": {"functions": 1.0, "closures": 0.0, "total": 1.0, "closures_min": 0.0, "closures_max": 0.0, "functions_min": 0.0, "functions_max": 1.0},
"nom": {"functions": 1.0, "closures": 0.0, "functions_average": 0.5, "closures_average": 0.0, "total": 1.0, "average": 0.5, "closures_min": 0.0, "closures_max": 0.0, "functions_min": 0.0, "functions_max": 1.0},
"mi": {"mi_original": 139.974_331_558_152_1,
"mi_sei": 161.414_455_240_662_22,
"mi_visual_studio": 81.856_334_244_533_39}},
Expand All @@ -677,7 +677,7 @@ mod tests {
"n1": 2.0,
"volume": 4.754_887_502_163_468},
"loc": {"cloc": 0.0, "ploc": 2.0, "lloc": 1.0, "sloc": 2.0, "blank": 0.0},
"nom": {"functions": 1.0, "closures": 0.0, "total": 1.0, "closures_min": 0.0, "closures_max": 0.0, "functions_min": 1.0, "functions_max": 1.0},
"nom": {"functions": 1.0, "closures": 0.0, "functions_average": 1.0, "closures_average": 0.0, "total": 1.0, "average": 1.0, "closures_min": 0.0, "closures_max": 0.0, "functions_min": 1.0, "functions_max": 1.0},
"mi": {"mi_original": 151.433_315_883_223_23,
"mi_sei": 142.873_061_717_489_78,
"mi_visual_studio": 88.557_494_668_551_6}},
Expand Down Expand Up @@ -730,7 +730,7 @@ mod tests {
"n1": 2.0,
"volume": 4.754_887_502_163_468},
"loc": {"cloc": 0.0, "ploc": 2.0, "lloc": 1.0, "sloc": 2.0, "blank": 0.0},
"nom": {"functions": 1.0, "closures": 0.0, "total": 1.0, "closures_min": 0.0, "closures_max": 0.0, "functions_min": 0.0, "functions_max": 1.0},
"nom": {"functions": 1.0, "closures": 0.0, "functions_average": 0.5, "closures_average": 0.0, "total": 1.0, "average": 0.5, "closures_min": 0.0, "closures_max": 0.0, "functions_min": 0.0, "functions_max": 1.0},
"mi": {"mi_original": 151.203_315_883_223_2,
"mi_sei": 142.643_061_717_489_76,
"mi_visual_studio": 88.422_991_744_574_97}},
Expand Down Expand Up @@ -779,7 +779,7 @@ mod tests {
"n1": 2.0,
"volume": 4.754_887_502_163_468},
"loc": {"cloc": 0.0, "ploc": 2.0, "lloc": 1.0, "sloc": 2.0, "blank": 0.0},
"nom": {"functions": 1.0, "closures": 0.0, "total": 1.0, "closures_min": 0.0, "closures_max": 0.0, "functions_min": 0.0, "functions_max": 1.0},
"nom": {"functions": 1.0, "closures": 0.0, "functions_average": 0.5, "closures_average": 0.0, "total": 1.0, "average": 0.5, "closures_min": 0.0, "closures_max": 0.0, "functions_min": 0.0, "functions_max": 1.0},
"mi": {"mi_original": 151.203_315_883_223_2,
"mi_sei": 142.643_061_717_489_76,
"mi_visual_studio": 88.422_991_744_574_97}},
Expand All @@ -806,7 +806,7 @@ mod tests {
"n1": 2.0,
"volume": 4.754_887_502_163_468},
"loc": {"cloc": 0.0, "ploc": 2.0, "lloc": 1.0, "sloc": 2.0, "blank": 0.0},
"nom": {"functions": 1.0, "closures": 0.0, "total": 1.0, "closures_min": 0.0, "closures_max": 0.0, "functions_min": 1.0, "functions_max": 1.0},
"nom": {"functions": 1.0, "closures": 0.0, "functions_average": 1.0, "closures_average": 0.0, "total": 1.0, "average": 1.0, "closures_min": 0.0, "closures_max": 0.0, "functions_min": 1.0, "functions_max": 1.0},
"mi": {"mi_original": 151.433_315_883_223_23,
"mi_sei": 142.873_061_717_489_78,
"mi_visual_studio": 88.557_494_668_551_6}},
Expand Down
107 changes: 106 additions & 1 deletion src/metrics/nom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Stats {
functions_max: usize,
closures_min: usize,
closures_max: usize,
space_count: usize,
}
impl Default for Stats {
fn default() -> Self {
Expand All @@ -29,6 +30,7 @@ impl Default for Stats {
functions_max: 0,
closures_min: usize::MAX,
closures_max: 0,
space_count: 1,
}
}
}
Expand All @@ -37,10 +39,13 @@ impl Serialize for Stats {
where
S: Serializer,
{
let mut st = serializer.serialize_struct("nom", 7)?;
let mut st = serializer.serialize_struct("nom", 10)?;
st.serialize_field("functions", &self.functions_sum())?;
st.serialize_field("closures", &self.closures_sum())?;
st.serialize_field("functions_average", &self.functions_average())?;
st.serialize_field("closures_average", &self.closures_average())?;
st.serialize_field("total", &self.total())?;
st.serialize_field("average", &self.average())?;
st.serialize_field("functions_min", &self.functions_min())?;
st.serialize_field("functions_max", &self.functions_max())?;
st.serialize_field("closures_min", &self.closures_min())?;
Expand All @@ -55,14 +60,20 @@ impl fmt::Display for Stats {
f,
"functions: {}, \
closures: {}, \
functions_average: {}, \
closures_average: {}, \
total: {} \
average: {} \
functions_min: {} \
functions_max: {} \
closures_min: {} \
closures_max: {}",
self.functions_sum(),
self.closures_sum(),
self.functions_average(),
self.closures_average(),
self.total(),
self.average(),
self.functions_min(),
self.functions_max(),
self.closures_min(),
Expand All @@ -80,6 +91,7 @@ impl Stats {
self.closures_max = self.closures_max.max(other.closures_max);
self.functions_sum += other.functions_sum;
self.closures_sum += other.closures_sum;
self.space_count += other.space_count;
}

/// Counts the number of function definitions in a scope
Expand Down Expand Up @@ -108,6 +120,24 @@ impl Stats {
self.closures_sum as f64
}

/// Returns the average number of function definitions over all spaces
#[inline(always)]
pub fn functions_average(&self) -> f64 {
self.functions_sum() / self.space_count as f64
}

/// Returns the average number of closures over all spaces
#[inline(always)]
pub fn closures_average(&self) -> f64 {
self.closures_sum() / self.space_count as f64
}

/// Returns the average number of function definitions and closures over all spaces
#[inline(always)]
pub fn average(&self) -> f64 {
self.total() / self.space_count as f64
}

/// Counts the number of function definitions in a scope
#[inline(always)]
pub fn functions_min(&self) -> f64 {
Expand Down Expand Up @@ -202,6 +232,11 @@ mod tests {
(functions_min, 0, usize),
(closures_min, 0, usize),
(closures_max, 1, usize),
],
[
(functions_average, 0.75), // number of spaces = 4
(closures_average, 0.25),
(average, 1.0)
]
);
}
Expand All @@ -223,6 +258,11 @@ mod tests {
(functions_min, 0, usize),
(closures_min, 0, usize),
(closures_max, 1, usize),
],
[
(functions_average, 0.5), // number of spaces = 4
(closures_average, 0.25),
(average, 0.75)
]
);
}
Expand All @@ -246,6 +286,11 @@ mod tests {
(functions_min, 0, usize),
(closures_min, 0, usize),
(closures_max, 0, usize),
],
[
(functions_average, 0.5), // number of spaces = 2
(closures_average, 0.0),
(average, 0.5)
]
);
}
Expand All @@ -269,6 +314,11 @@ mod tests {
(functions_min, 0, usize),
(closures_min, 0, usize),
(closures_max, 1, usize),
],
[
(functions_average, 0.5), // number of spaces = 4
(closures_average, 0.25),
(average, 0.75)
]
);
}
Expand Down Expand Up @@ -300,6 +350,11 @@ mod tests {
(functions_min, 0, usize),
(closures_min, 0, usize),
(closures_max, 1, usize),
],
[
(functions_average, 0.6), // number of spaces = 5
(closures_average, 0.2),
(average, 0.8)
]
);
}
Expand All @@ -321,6 +376,11 @@ mod tests {
(functions_min, 0, usize),
(closures_min, 0, usize),
(closures_max, 0, usize),
],
[
(functions_average, 0.5), // number of spaces = 2
(closures_average, 0.0),
(average, 0.5)
]
);
}
Expand All @@ -340,6 +400,11 @@ mod tests {
(functions_min, 0, usize),
(closures_min, 0, usize),
(closures_max, 0, usize),
],
[
(functions_average, 0.5), // number of spaces = 2
(closures_average, 0.0),
(average, 0.5)
]
);
}
Expand All @@ -361,6 +426,11 @@ mod tests {
(functions_min, 0, usize),
(closures_min, 0, usize),
(closures_max, 0, usize),
],
[
(functions_average, 0.5), // number of spaces = 2
(closures_average, 0.0),
(average, 0.5)
]
);
}
Expand All @@ -382,6 +452,11 @@ mod tests {
(functions_min, 0, usize),
(closures_min, 0, usize),
(closures_max, 0, usize),
],
[
(functions_average, 0.5), // number of spaces = 2
(closures_average, 0.0),
(average, 0.5)
]
);
}
Expand All @@ -405,6 +480,11 @@ mod tests {
(functions_min, 0, usize),
(closures_min, 0, usize),
(closures_max, 0, usize),
],
[
(functions_average, 0.5), // number of spaces = 2
(closures_average, 0.0),
(average, 0.5)
]
);
}
Expand All @@ -428,6 +508,11 @@ mod tests {
(functions_min, 0, usize),
(closures_min, 0, usize),
(closures_max, 1, usize),
],
[
(functions_average, 0.0), // number of spaces = 3
(closures_average, 0.6666666666666666),
(average, 0.6666666666666666)
]
);
}
Expand All @@ -449,6 +534,11 @@ mod tests {
(functions_min, 0, usize),
(closures_min, 0, usize),
(closures_max, 1, usize),
],
[
(functions_average, 0.3333333333333333), // number of spaces = 3
(closures_average, 0.3333333333333333),
(average, 0.6666666666666666)
]
);
}
Expand All @@ -468,6 +558,11 @@ mod tests {
(functions_min, 0, usize),
(closures_min, 0, usize),
(closures_max, 0, usize),
],
[
(functions_average, 0.5), // number of spaces = 2
(closures_average, 0.0),
(average, 0.5)
]
);
}
Expand All @@ -487,6 +582,11 @@ mod tests {
(functions_min, 0, usize),
(closures_min, 0, usize),
(closures_max, 1, usize),
],
[
(functions_average, 0.0), // number of spaces = 2
(closures_average, 0.5),
(average, 0.5)
]
);
}
Expand All @@ -508,6 +608,11 @@ mod tests {
(functions_min, 0, usize),
(closures_min, 0, usize),
(closures_max, 1, usize),
],
[
(functions_average, 0.0), // number of spaces = 2
(closures_average, 0.5),
(average, 0.5)
]
);
}
Expand Down