commit 2b34943a4846f9a48eb3105e41473f7e5a6e81ba Author: moanos Date: Thu Jul 18 19:51:24 2024 +0200 feat: Initial commit diff --git a/assets/calculator.js b/assets/calculator.js new file mode 100644 index 0000000..05b6eff --- /dev/null +++ b/assets/calculator.js @@ -0,0 +1,89 @@ +const MINIMUM_BASE_AREA = 0.5; +const MINIMUM_AREA_THREE_RATS = 1.8; +const AREA_PER_ADDITIONAL_RAT = 0.2; +const MAXIMUM_FALL_HEIGHT = 0.5; +const MINIMUM_LENGTH = 0.8; + +const FAILED_BASE_AREA = "base_area"; +const FAILED_OVERALL_AREA = "overall_area"; +const FAILED_FALL_HEIGHT = "fall_height"; +const FAILED_NUM_RATS = "num_rats"; +const FAILED_LENGTH = "length"; + +const FAIL_CRITERIA = { + [FAILED_BASE_AREA]: `Die Mindestgrundfläche des Käfigs muss ${MINIMUM_BASE_AREA}m² (also z.B. 100x50cm) betragen.`, + [FAILED_OVERALL_AREA]: "Die Gesamtfläche im Käfig ist zu klein.", + [FAILED_FALL_HEIGHT]: `Die mögliche Fallhöhe darf nicht mehr als ${(MAXIMUM_FALL_HEIGHT * 100).toFixed(3)}cm betragen.`, + [FAILED_NUM_RATS]: "Es müssen mindestens 3 Ratten zusammenleben, Paarhaltung ist nicht artgerecht.", + [FAILED_LENGTH]: `Eine Seite des Käfig muss mindestens ${(MINIMUM_LENGTH * 100).toFixed(3)}cm lang sein um Rennen zu ermöglichen.`, +}; + +class Dimensions { + constructor(length, width, height) { + this.length = length; + this.width = width; + this.height = height; + } + + toString() { + return `${this.length}x${this.width}x${this.height}`; + } + + static fromDict(data) { + const { length, width, height } = data; + return new Dimensions(length, width, height); + } +} + +function overallAreaNeeded(numOfRats) { + if (numOfRats < 3 || numOfRats > 15) { + throw new Error("This formula works only from 3 to 15 rats"); + } + return MINIMUM_AREA_THREE_RATS + (numOfRats - 3) * AREA_PER_ADDITIONAL_RAT; +} + +function cageCheck(dimensions, numRats, numFullFloors) { + let failedCriteria = {}; + + if (numRats < 2 || numRats > 15) { + failedCriteria[FAILED_NUM_RATS] = FAIL_CRITERIA[FAILED_NUM_RATS]; + } + + const baseArea = dimensions.length * dimensions.width; + if (baseArea < MINIMUM_BASE_AREA) { + failedCriteria[FAILED_BASE_AREA] = FAIL_CRITERIA[FAILED_BASE_AREA]; + } + + const areaNeeded = overallAreaNeeded(numRats); + if (baseArea * numFullFloors < areaNeeded) { + failedCriteria[FAILED_OVERALL_AREA] = FAIL_CRITERIA[FAILED_OVERALL_AREA]; + } + + if (dimensions.height / numFullFloors > MAXIMUM_FALL_HEIGHT) { + failedCriteria[FAILED_FALL_HEIGHT] = FAIL_CRITERIA[FAILED_FALL_HEIGHT]; + } + + if (dimensions.width < MINIMUM_LENGTH && dimensions.length < MINIMUM_LENGTH) { + failedCriteria[FAILED_LENGTH] = FAIL_CRITERIA[FAILED_LENGTH]; + } + + return failedCriteria; +} + +const expectedAreaPerNumRats = { 3: 1.8, 4: 2.0 }; +for (let numRats in expectedAreaPerNumRats) { + console.log(`Area needed for ${numRats}: Calculated=${overallAreaNeeded(parseInt(numRats))}`); +} + +const exampleCageChecks = [ + [[], new Dimensions(1, 0.50, 1), 4, 4], + [[FAIL_CRITERIA[FAILED_BASE_AREA]], new Dimensions(0.99, 0.50, 1), 3, 4], + [[FAIL_CRITERIA[FAILED_OVERALL_AREA]], new Dimensions(0.99, 0.50, 1), 4, 4], + [[FAIL_CRITERIA[FAILED_OVERALL_AREA]], new Dimensions(0.79, 0.79, 1), 4, 4], +]; + +for (let idx in exampleCageChecks) { + let check = exampleCageChecks[idx]; + console.log(`Example ${idx}: ${check[1]} n(rats): ${check[2]}, n(floors): ${check[3]}`); + console.log(`Result: ${JSON.stringify(cageCheck(check[1], check[2], check[3]))}\n`); +} diff --git a/assets/css/style.css b/assets/css/style.css new file mode 100644 index 0000000..ce9c407 --- /dev/null +++ b/assets/css/style.css @@ -0,0 +1,39 @@ +.slidecontainer { + width: 100%; +} + +.slider { + -webkit-appearance: none; + width: 100%; + height: 10px; + border-radius: 5px; + background: #d3d3d3; + outline: none; + opacity: 0.7; + -webkit-transition: .2s; + transition: opacity .2s; +} + +.slider:hover { + opacity: 1; +} + +.slider::-webkit-slider-thumb { + -webkit-appearance: none; + appearance: none; + width: 23px; + height: 24px; + border: 0; + background: url('/assets/img/logo_transparent.png'); + background-size: 100% 100%; + cursor: pointer; +} + +.slider::-moz-range-thumb { + width: 23px; + height: 24px; + border: 0; + background: url('/assets/img/logo_transparent.png'); + background-size: 100% 100%; + cursor: pointer; +} \ No newline at end of file diff --git a/assets/img/logo.png b/assets/img/logo.png new file mode 100644 index 0000000..8efc377 Binary files /dev/null and b/assets/img/logo.png differ diff --git a/assets/img/logo_transparent.png b/assets/img/logo_transparent.png new file mode 100644 index 0000000..99e3126 Binary files /dev/null and b/assets/img/logo_transparent.png differ diff --git a/assets/img/logo_transparent_small.png b/assets/img/logo_transparent_small.png new file mode 100644 index 0000000..b57c9e3 Binary files /dev/null and b/assets/img/logo_transparent_small.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..bc92c3f --- /dev/null +++ b/index.html @@ -0,0 +1,72 @@ + + + + + Knastrechner + + + + +

Range Slider Picture

+ +
+ + + + + + +
+
+
+ + + + + \ No newline at end of file