Commit dc307bb7 authored by Clement Brizard's avatar Clement Brizard
Browse files

Merge branch '53-embodied-pour-un-composant-assimile' into 'master'

Resolve "Pouvoir calculer un impact embodied pour un composant assimilé à un autre"

Closes #53

See merge request tx-techno-num/impactometre!49
parents 47763537 c45aad15
......@@ -8,28 +8,28 @@ const {
const hardware = {
/**
* ASSIMILATION CANDIDATES
* If we cannot have the damage values directly
* from Ecovinvent database, we assimilate the damage
* caused by the object to the damage caused by a known
* object.
*/
* ASSIMILATION CANDIDATES
* If we cannot have the damage values directly
* from Ecovinvent database, we assimilate the damage
* caused by the object to the damage caused by a known
* object.
*/
ASSIMILATION_COMPUTER_TOWER_1G: {
name: 'ASSIMILATION_COMPUTER_TOWER_1G',
french: '1 g d\'une tour d\'ordinateur',
isSizeDependent: false,
embodied: {
humanHealth: 0.004353982,
ecosystemQuality: 0.000843363,
climateChange: 0.002035398,
resources: 0.00185841
humanHealth: 4.35 * Math.pow(10, -3),
ecosystemQuality: 8.43 * Math.pow(10, -4),
climateChange: 2.04 * Math.pow(10, -3),
resources: 1.86 * Math.pow(10, -3)
},
lifetime: hardwareLifetime.DESKTOP,
operatingTimePerDay: hardwareOperatingTimePerDay.NOT_VISIO_DEDICATED
},
/**
* DESKTOP AND LAPTOP
* */
*/
DESKTOP: {
name: 'DESKTOP',
french: 'ordinateur fixe',
......@@ -173,7 +173,7 @@ const hardware = {
french: 'micro',
category: meetingComponents.HARDWARE,
isSizeDependent: false,
isEmbodiedAssimilatedTo: 'ASSIMILATION_COMPUTER_TOWER_1',
embodiedAssimilatedTo: 'ASSIMILATION_COMPUTER_TOWER_1G',
// source: Jabra Speak 410 - https://www.jabra.fr/business/speakerphones/jabra-speak-series/jabra-speak-410#/#7410-209
weight: 180.3,
operatingOneMinVisio: {
......@@ -198,7 +198,7 @@ const hardware = {
lower: 162,
upper: 628
},
isEmbodiedAssimilatedTo: 'ASSIMILATION_COMPUTER_TOWER_1G',
embodiedAssimilatedTo: 'ASSIMILATION_COMPUTER_TOWER_1G',
operatingOneMinVisio: {
humanHealth: 9.84 * Math.pow(10, -12),
ecosystemQuality: 4.53 * Math.pow(10, -6),
......@@ -296,7 +296,7 @@ const hardware = {
isSizeDependent: false,
// camera = 670 g, hub = 170 g, speakerphone = 920g, remote = 51 g, TOTAL = 1811 g
weight: 1811,
isEmbodiedAssimilatedTo: 'ASSIMILATION_COMPUTER_TOWER_1G',
embodiedAssimilatedTo: 'ASSIMILATION_COMPUTER_TOWER_1G',
operatingOneMinStandby: {
humanHealth: 5.9 * Math.pow(10, -12),
ecosystemQuality: 2.72 * Math.pow(10, -6),
......
......@@ -35,9 +35,15 @@ class Hardware extends Component {
this._name = json.name
this._quantity = quantity
this._size = size
this._weight = json.weight
this._shareForVisio = shareForVisio
this._isSizeDependent = json.isSizeDependent
this._embodied = json.embodied
this._embodiedAssimilatedTo = json.embodiedAssimilatedTo
this._embodied = (json.embodiedAssimilatedTo)
? Object.assign({}, hardwareDatabase[json.embodiedAssimilatedTo].embodied)
: json.embodied
this._operatingOneMinVisio = json.operatingOneMinVisio
this._operatingOneMinStandby = json.operatingOneMinStandby
this._lifetime = json.lifetime
......@@ -94,6 +100,16 @@ class Hardware extends Component {
return this._size
}
/**
* Get the optional weight. Useful if the embodied
* damage is assilimated to the damage of 1g of another
* hardware.
* @returns {Number} The optional weight.
*/
get weight () {
return this._weight
}
/**
* Get the hardware share dedicated to visio.
* E.g. if the hardware is a laptop, the user
......@@ -115,6 +131,15 @@ class Hardware extends Component {
return this._isSizeDependent
}
/**
* Get the optional hardware name to which the current
* hardware's embodied damage is assimilated to.
* @see hardware.js in database
*/
get embodiedAssimilatedTo () {
return this._embodiedAssimilatedTo
}
/**
* Get the embodied damage info for the hardware.
* It's a raw JSON that may contain upper and lower
......@@ -194,6 +219,10 @@ class Hardware extends Component {
this._size = size
}
set weight (weight) {
this._weight = weight
}
set shareForVisio (shareForVisio) {
this._shareForVisio = shareForVisio
}
......@@ -266,7 +295,6 @@ class Hardware extends Component {
damage[category] *= this.shareForVisio * this.size * this.getVisioOrStandbyDuration(damageType, meetingDuration)
})
} else {
damage = new Damage({ component: this, ...this.getTypedDamage(damageType, bound) })
damage.mutate(category => {
damage[category] *= this.shareForVisio * this.getVisioOrStandbyDuration(damageType, meetingDuration)
})
......@@ -323,6 +351,29 @@ class Hardware extends Component {
) {
// Damage is for visio time
damageType = hardwareDamageTypes.EMBODIED
// Embodied damage may be assimilated to the one of another hardware
if (this.embodiedAssimilatedTo) {
/* Assimilated embodied is for 1 g, so we have to multiply
it by the weight of our hardware */
let boundSpecificWeight
// Get weight specific value if available
if (this.weight.upper && this.weight.lower) {
boundSpecificWeight = (bound != null)
? this.weight[bound]
: this.weight[bounds.UPPER]
} else {
boundSpecificWeight = this.weight
}
const weightEmbodied = Object.assign({}, this.embodied)
Object.keys(weightEmbodied).map(category => {
weightEmbodied[category] *= boundSpecificWeight
})
return weightEmbodied
}
}
if (!this[damageType]) {
......
......@@ -91,6 +91,21 @@ describe('Hardware class', () => {
assert.deepStrictEqual(expected, component._components)
})
it('should create a hardware for all hardwares which embodied is assimilated to another one', () => {
Object.values(hardwareDatabase)
.filter(json => json.embodiedAssimilatedTo)
.forEach(json => {
const instance = new Hardware({ name: json.name })
assert.deepStrictEqual(
instance.embodied,
hardwareDatabase[json.embodiedAssimilatedTo].embodied
)
Object.values(instance.embodied).forEach(categoryDamageValue => {
assert.isNotNaN(categoryDamageValue)
})
})
})
})
describe('#computeVisioOrStandbyTimeOverLife()', () => {
describe('operating', () => {
......@@ -261,7 +276,7 @@ describe('Hardware class', () => {
}
Object.values(hardwareDatabase).filter(json => {
return (!json[damageType])
return (!json[damageType] && !json.embodiedAssimilatedTo)
}).forEach(json => {
const component = new Hardware({ name: json.name })
assert.strictEqual(
......@@ -271,6 +286,30 @@ describe('Hardware class', () => {
})
})
})
it('should get assimilated embodied damages', () => {
Object.values(hardwareDatabase)
.filter(json => json.embodiedAssimilatedTo)
.forEach(json => {
const instance = new Hardware({ name: json.name })
const weight = (json.weight.upper && json.weight.lower)
? json.weight.upper
: json.weight
const expected = hardwareDatabase[json.embodiedAssimilatedTo].embodied
Object.keys(expected).map(category => {
expected[category] *= weight
})
assert.deepStrictEqual(
instance.getTypedDamage(hardwareDamageTypes.EMBODIED_VISIO),
expected
)
Object.values(expected).forEach(categoryDamageValue => {
assert.isNotNaN(categoryDamageValue)
})
})
})
it('should return the unique available value', () => {
Object.values(hardwareDamageTypes).forEach(damageType => {
if (
......@@ -382,7 +421,7 @@ describe('Hardware class', () => {
Object.values(hardwareDatabase)
.filter(json => {
return (
!json[damageType] &&
!json[damageType] && !json.embodiedAssimilatedTo &&
!(
Array.isArray(json.components) &&
json.components.length
......@@ -469,6 +508,30 @@ describe('Hardware class', () => {
})
})
})
it('should compute assimilated embodied damages', () => {
Object.values(hardwareDatabase)
.filter(json => json.embodiedAssimilatedTo)
.forEach(json => {
const instance = new Hardware({ name: json.name })
const weight = (json.weight.upper && json.weight.lower)
? json.weight.upper
: json.weight
const expected = hardwareDatabase[json.embodiedAssimilatedTo].embodied
Object.keys(expected).map(category => {
expected[category] *= weight
})
assert.deepStrictEqual(
instance.getTypedDamage(hardwareDamageTypes.EMBODIED_VISIO),
expected
)
Object.values(expected).forEach(categoryDamageValue => {
assert.isNotNaN(categoryDamageValue)
})
})
})
it('should compute the damage of a composite hardware', () => {
Object.values(hardwareDamageTypes).forEach(damageType => {
Object.values(hardwareDatabase)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment