| 193 | } |
| 194 | |
| 195 | func (i *item) MarshalJSON() ([]byte, error) { |
| 196 | // How we want to emit an item as JSON. |
| 197 | value, _ := i.value.ToUint64() |
| 198 | |
| 199 | stat := struct { |
| 200 | Description string `json:"description"` |
| 201 | Value uint64 `json:"value"` |
| 202 | Unit string `json:"unit"` |
| 203 | Prefixes string `json:"prefixes"` |
| 204 | ReferenceValue float64 `json:"referenceValue"` |
| 205 | LevelOfConcern float64 `json:"levelOfConcern"` |
| 206 | ObjectName string `json:"objectName,omitempty"` |
| 207 | ObjectDescription string `json:"objectDescription,omitempty"` |
| 208 | }{ |
| 209 | Description: i.description, |
| 210 | Value: value, |
| 211 | Unit: i.unit, |
| 212 | Prefixes: i.humaner.Name(), |
| 213 | ReferenceValue: i.scale, |
| 214 | LevelOfConcern: float64(value) / i.scale, |
| 215 | } |
| 216 | |
| 217 | if i.path != nil && i.path.OID != git.NullOID { |
| 218 | stat.ObjectName = i.path.OID.String() |
| 219 | stat.ObjectDescription = i.path.Path() |
| 220 | } |
| 221 | |
| 222 | return json.Marshal(stat) |
| 223 | } |
| 224 | |
| 225 | // Indented returns an `item` that is just like `i`, but indented by |
| 226 | // `depth` more levels. |