Skip to content

Commit

Permalink
Remove input object legacy parts of the script
Browse files Browse the repository at this point in the history
  • Loading branch information
HildoBijl committed Jan 17, 2024
1 parent 4875057 commit db2fe6a
Show file tree
Hide file tree
Showing 9 changed files with 2 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ function getSolution({ p1, V1, V2, n }) {
const V1s = V1.simplify()
const V2s = V2.simplify()
cv = cv.simplify()
if (typeof n === 'number') // Legacy: in older exercises n was stored as number. Adjust accordingly.
n = new FloatUnit({ float: n, unit: '' })
const p2 = p1s.multiply(Math.pow(V1s.number / V2s.number, n.number))
const p2s = p2.simplify()
const diff = p2s.multiply(V2s).subtract(p1s.multiply(V1s)).setUnit('J')
Expand Down
3 changes: 0 additions & 3 deletions shared/inputTypes/Boolean.js

This file was deleted.

17 changes: 1 addition & 16 deletions shared/inputTypes/Float/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ module.exports.SItoFO = (value) => {
if (power === '-')
throw new InterpretationError(`DecimalSeparator`, undefined, 'Could not interpret a number consisting of only a decimal separator.')

// Input object legacy: in older data formats an empty power was stored as an empty string. Convert this.
if (power === '')
power = undefined

// Set up a float with the given properties.
return new Float({
number: parseFloat(number) * Math.pow(10, power || 0),
Expand All @@ -36,15 +32,4 @@ module.exports.FOtoSI = (float) => {
}
}

module.exports.SOtoFO = SO => {
// Input object legacy: if the number is a string, the SO is actually an SI. This is the old way of storing floats from the state.
if (typeof SO.number === 'string')
return module.exports.SItoFO(SO)

// Input object legacy: if the power is an empty string, turn it into undefined.
if (SO.power === '')
SO = { ...SO, power: undefined }

// The regular way of getting the FO.
return new Float(SO)
}
module.exports.SOtoFO = SO => new Float(SO)
8 changes: 1 addition & 7 deletions shared/inputTypes/FloatUnit/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,4 @@ module.exports.FOtoSI = FO => ({
unit: FO.unit.SI,
})

module.exports.SOtoFO = SO => {
// Input object legacy: use the individual SOtoFO functions. If the old data types are removed, a simple "return new FloatUnit(SO)" would suffice.
return new FloatUnit({
float: floatSOtoFO(SO.float),
unit: unitSOtoFO(SO.unit),
})
}
module.exports.SOtoFO = SO => FloatUnit(SO)
3 changes: 0 additions & 3 deletions shared/inputTypes/Integer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ module.exports.SItoFO = (value) => {
module.exports.FOtoSI = (integer) => {
return integer.toString()
}

// Input object legacy: the integer used to be stored inside an object, even for the state. The function below unpacks it. It can be removed once the old exercise data is deleted.
module.exports.SOtoFO = module.exports.SItoFO
9 changes: 0 additions & 9 deletions shared/inputTypes/String.js

This file was deleted.

4 changes: 0 additions & 4 deletions shared/inputTypes/Unit/UnitElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ class UnitElement {
if (typeof input === 'string')
input = interpretStr(input)

// Input object legacy: remove any 'invalid' property that may still remain.
input = { ...input }
delete input.invalid

// Include default values.
const { prefix, unit, power } = processOptions(input, defaultUnitElement)

Expand Down
4 changes: 0 additions & 4 deletions shared/inputTypes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ function requireAndProcess(name) {
module.exports = {
...require('./main'),

// Basic types. Must be removed after input object legacy data is deleted.
...requireAndProcess('Boolean'),
...requireAndProcess('String'),

// Number- and physics-based types.
...requireAndProcess('Integer'),
...requireAndProcess('Float'),
Expand Down
2 changes: 0 additions & 2 deletions shared/inputTypes/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const { isInteger, isObject, isBasicObject, applyMapping } = require('../util')

// Input object legacy: the types Boolean, String and MultipleChoice can be removed after the corresponding old exercise data is removed.
const types = [
'Boolean', 'String', 'MultipleChoice', // Basic types. Must be removed after input object legacy data is deleted.
'Integer', 'Float', 'Unit', 'FloatUnit', // Number- and physics-based types.
'Expression', 'Equation', // Expression-based types.
'Vector', 'Span', // Object-based types.
Expand Down

0 comments on commit db2fe6a

Please sign in to comment.