UNPKG

@trusthab/composable-resources

Version:

migrating https://github.com/knetikmedia/hab-api/tree/integration/app/resources/composable

103 lines (88 loc) 7.22 kB
const composer = require('../../mixin_loader'); module.exports = (App) => { /* The Image Permanence Institute and the Canadian Conservation Institute (CCI) in Ottawa have created graphs to model the likelihood of mold growth. Again, mold is a function of temperature, relative humidity and time. In a warm, moist environment mold appears rapidly. At 100 percent RH, 80 degrees Fahrenheit, mold starts within two days. However, lower the relative humidity 25 percent and it will take 90 days for mold to appear. Mold growth is optimum, appearing within 10 days, between 50 to 104 degrees Fahrenheit and 85 to 100 percent RH. According to IPI's research, mold will not grow below 65 percent RH, below 30 degrees Fahrenheit or above 110 degrees Fahrenheit. https://www.collectioncare.org/pubs/v2n2p1.html http://www.dpcalc.org/index.php */ const MODEL = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 21, 19, 18, 17, 16, 15, 14, 13, 12, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 15, 14, 13, 12, 11, 10, 10, 9, 9, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 12, 11, 10, 9, 9, 8, 8, 7, 7, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 11, 10, 9, 8, 8, 7, 7, 6, 6, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 10, 9, 8, 8, 7, 7, 6, 6, 5, 5, 5, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 12, 10, 9, 8, 7, 7, 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, 69, 53, 41, 32, 26, 21, 17, 14, 12, 10, 9, 8, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 123, 90, 67, 51, 40, 31, 25, 21, 17, 14, 12, 10, 9, 8, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 0, 0, 0, 0, 0, 168, 121, 88, 66, 50, 39, 31, 25, 20, 17, 14, 12, 10, 9, 8, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 0, 0, 0, 0, 236, 165, 119, 87, 65, 50, 38, 30, 24, 20, 16, 14, 11, 10, 8, 7, 6, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 0, 0, 0, 340, 232, 163, 117, 86, 64, 49, 38, 30, 24, 19, 16, 13, 11, 10, 8, 7, 6, 6, 5, 5, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 0, 0, 0, 335, 229, 161, 115, 85, 63, 48, 37, 30, 24, 19, 16, 13, 11, 10, 8, 7, 6, 6, 5, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 0, 0, 498, 332, 227, 159, 114, 84, 63, 48, 37, 29, 23, 19, 16, 13, 11, 9, 8, 7, 6, 6, 5, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 0, 763, 493, 328, 225, 157, 113, 83, 62, 47, 37, 29, 23, 19, 16, 13, 11, 9, 8, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 756, 489, 326, 223, 156, 112, 82, 61, 47, 36, 29, 23, 19, 15, 13, 11, 9, 8, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 751, 486, 323, 221, 155, 111, 81, 61, 46, 36, 28, 23, 19, 15, 13, 11, 9, 8, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 747, 483, 322, 220, 154, 111, 81, 61, 46, 36, 28, 23, 18, 15, 13, 11, 9, 8, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 1186, 744, 481, 320, 219, 154, 110, 81, 60, 46, 36, 28, 23, 18, 15, 13, 11, 9, 8, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 742, 480, 320, 219, 153, 110, 81, 60, 46, 36, 28, 23, 18, 15, 13, 11, 9, 8, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 742, 480, 319, 218, 153, 110, 80, 60, 46, 36, 28, 23, 18, 15, 13, 11, 9, 8, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 742, 480, 320, 219, 153, 110, 81, 60, 46, 36, 28, 23, 18, 15, 13, 11, 9, 8, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 482, 321, 219, 154, 110, 81, 60, 46, 36, 28, 23, 18, 15, 13, 11, 9, 8, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 484, 322, 220, 154, 111, 81, 61, 46, 36, 28, 23, 18, 15, 13, 11, 9, 8, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 325, 222, 156, 112, 82, 61, 47, 36, 29, 23, 19, 15, 13, 11, 9, 8, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 224, 157, 113, 83, 62, 47, 37, 29, 23, 19, 16, 13, 11, 9, 8, 7, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 160,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0, 0, 23, 21, 19, 18, 17, 16, 15, 14, 13, 12, 12]; class ZonesDaysToMoldResource { static mixins() { return ['Kpi']; } getMetricId() { return `zones_days_to_mold`; } getMetricType() { return 'gauge'; } getValue() { const { key, value } = this.get('diff'); let { current_temp, humidity } = this.get('obj'); if (key === 'humidity') { humidity = value; } if (key === 'current_temp') { current_temp = value; } const current_temp_celcius = (current_temp - 32) * 5 / 9; if (current_temp_celcius > 45 || current_temp_celcius < 2 || humidity < 65) { return null; } const days_to_mold = MODEL[(Math.round(current_temp_celcius) - 2) * 36 + Math.round(humidity) - 65]; if (days_to_mold < 1) { return null; } return days_to_mold; } } return composer(ZonesDaysToMoldResource, App); };