Add common area share into calculation

This commit is contained in:
Niklas Meinzer
2024-06-03 20:45:11 +02:00
parent 2fe867c399
commit a42b910de4
3 changed files with 103 additions and 17 deletions

View File

@@ -7,7 +7,7 @@
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
content="Solimieten-Tool der Allmende Gundelfingen"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--

View File

@@ -5,44 +5,102 @@ class Flat {
this.sizePrivate = sizePrivate;
this.isWbs = isWbs;
this.sizeShared = 0;
// Normal flats have as many people as rooms
// WGs and cluster flats have one more room
if (!wgRoomList) {
this.wgRoomList = [];
this.numPeople = numRooms;
} else {
this.wgRoomList = wgRoomList;
this.sizeShared = this.sizePrivate;
for (var i = 0; i < this.wgRoomList.length; i++) {
this.sizeShared -= this.wgRoomList[i].size;
}
this.numPeople = numRooms - 1;
}
}
// Returns a string representation of the flat
print() {
return this.name + " (" + this.numRooms + " Zimmer)";
}
// Calculates the share of the internal shared area the party has to pay for
// This is only applicable for WGs and clusters, i.e. when a room is selected.
calcInternalAreaShare(room = null) {
return room ? this.sizeShared / this.numPeople * room.numPeople : 0;
}
// Calculates the share of the project wide common area
// the party has to pay for.
// Currently done by number of people in the party.
calcCommonAreaShare(room = null) {
var numPeople;
if (room) {
numPeople = room.numPeople;
} else {
numPeople = this.numRooms;
}
return commonArea / numPeopleTotal * numPeople;
}
// Calculates the total area the party has to pay for
// Includes the private area, share of the common area and for
// WGs and clusters the share of the internal shared area
calcTotalPayedArea(room = null) {
var commonAreaShare = this.calcCommonAreaShare(room);
if (!room) {
return this.sizePrivate + commonAreaShare;
} else {
return room.size + commonAreaShare + this.calcInternalAreaShare(room);
}
}
}
class Room {
constructor(name, size, numPeople = 1) {
this.name = name;
this.size = size;
this.numPeople = numPeople;
}
print() {
return this.name + " (" + this.numRooms + " Zimmer)";
return this.name;
}
}
export const flatData = {
"north": {
0: [
new Flat("W 0.1", 4, 82.7, false, false, [{ label: "0.1 02", size: 12.8 }, { label: "0.1 03", size: 12.8 }, { label: "0.1 04", size: 14.6 }]), // Todo: make WG
new Flat("W 0.1", 4, 82.7, false, false, [
new Room("0.1 02", 12.8), new Room("0.1 03", 12.8), new Room("0.1 04", 14.6)
]),
new Flat("W 0.2", 2, 53.1, true),
new Flat("W 0.3", 3, 62, true)
],
1: [
new Flat("W 1.1", 4, 82.5, true),
new Flat("W 1.2", 1, 35.4, true),
new Flat("W 1.3", 4, 61, true, false, [{ label: "1.3 02", size: 11.88 }, { label: "1.3 03", size: 11.41 }, { label: "1.3 04", size: 11.89 }])
new Flat("W 1.3", 4, 61, true, false, [
new Room("1.3 02", 11.88), new Room("1.3 03", 11.41), new Room("1.3 04", 11.89)
])
],
2: [
new Flat("W 2.1", 4, 82.6, true),
new Flat("W 2.2", 2, 45.3, true),
new Flat("W 2.3", 5, 148.77, true, true, [{ label: "1 Person", size: 25.32 }, { label: "2 Personen", size: 44.52 }, { label: "1 Person (rollstuhlgerecht)", size: 39.8 }]),
new Flat("W 2.3", 5, 148.77, true, true, [
new Room("1 Person", 25.32), new Room("2 Personen", 44.52, 2), new Room("1 Person (rollstuhlgerecht)", 39.8)
]),
new Flat("W 2.4", 2, 62.5, true, true)
],
3: [
new Flat("W 3.1", 4, 82.6),
new Flat("W 3.2", 5, 148.77, true, true, [{ label: "1 Person", size: 25.32 }, { label: "2 Personen", size: 44.52 }, { label: "1 Person (rollstuhlgerecht)", size: 39.8 }]),
new Flat("W 3.2", 5, 148.77, true, true, [
new Room("1 Person", 25.32), new Room("2 Personen", 44.52, 2), new Room("1 Person (rollstuhlgerecht)", 39.8)
]),
new Flat("W 3.3", 3, 61.8, true)
]
},
@@ -54,7 +112,9 @@ export const flatData = {
],
1: [
new Flat("W 1.4", 2, 55.7),
new Flat("W 1.5 (WG)", 5, 83.86, true, false, [{ label: "1.5 02", size: 15.72 }, { label: "1.5 03", size: 9.81 }, { label: "1.5 05", size: 11.48 }, { label: "1.5 06", size: 13.45 }]),
new Flat("W 1.5 (WG)", 5, 83.86, true, false,
[new Room("1.5 02", 15.72), new Room("1.5 03", 9.81), new Room("1.5 05", 11.48), new Room("1.5 06", 13.45)]
),
new Flat("W 1.6.0", 1, 25.6),
new Flat("W 1.6", 5, 95.7),
],
@@ -68,3 +128,18 @@ export const flatData = {
export const minRent = 9.50;
export const maxRent = 15.60;
const commonArea = 388.80;
// Calculate total number of people
var _numPeople = 0;
for (const building of Object.keys(flatData)) {
for (const floor of Object.keys(flatData[building])) {
for (const flat of flatData[building][floor]) {
_numPeople += flat.numPeople;
}
}
}
const numPeopleTotal = _numPeople;

View File

@@ -58,6 +58,7 @@ export function FlatSelectionCard({ setSelectedFlat, onRoomSelected }) {
setRoomOptions(flat.wgRoomList);
}
setSelectedFlat(flatOptions[index]);
onRoomSelected(null);
}
function roomSelected(e) {
onRoomSelected(roomOptions[e.target.value]);
@@ -80,7 +81,7 @@ export function FlatSelectionCard({ setSelectedFlat, onRoomSelected }) {
{flatOptions.map((flat, index) => <option value={index} >{flat.print()}</option>)}
</Select>
{roomOptions.length > 0 ? (<Select placeholder='Zimmer auswählen' onChange={roomSelected}>
{roomOptions.map((room, index) => <option value={index} >{room.label} ({room.size} )</option>)}
{roomOptions.map((room, index) => <option value={index} >{room.print()} ({room.size} )</option>)}
</Select>) : null}
</Stack>
</CardBody>
@@ -101,10 +102,12 @@ export function FlatDetailsCard({ flat, room }) {
}
var sizeSharedBox = null;
var sizeSharedShare = 0;
var commonAreaShare = flat.calcCommonAreaShare(room);
var internalAreaShare = flat.calcInternalAreaShare(room);
if (flat.wgRoomList.length > 0) {
sizeSharedShare = flat.sizeShared / flat.wgRoomList.length;
sizeSharedBox = <Box>
<Heading size='xs' textTransform='uppercase'>
Interne Gemeinschaftsfläche
@@ -116,6 +119,8 @@ export function FlatDetailsCard({ flat, room }) {
}
var totalSizeToPay = flat.calcTotalPayedArea(room);
body = <CardBody>
<Stack divider={<StackDivider />} spacing='4'>
@@ -125,7 +130,7 @@ export function FlatDetailsCard({ flat, room }) {
Bezeichnung
</Heading>
<Text pt='2' fontSize='sm'>
{flat.name} {room ? "Zimmer: " + room.label : null}
{flat.name} {room ? "Zimmer: " + room.print() : null}
</Text>
</Box>
<Box>
@@ -139,12 +144,21 @@ export function FlatDetailsCard({ flat, room }) {
{sizeSharedBox}
<Box>
<Heading size='xs' textTransform='uppercase'>
Fläche
Anteil Gemeinschaftsfläche
</Heading>
<Text pt='2' fontSize='sm'>
{(sizePrivate + sizeSharedShare).toFixed(2)} {sizeSharedShare ? ("(" + sizePrivate + " m² Zimmer + " + sizeSharedShare.toFixed(2) + " m² Anteil interne Gemeinschaftsfläche)") : null}
{commonAreaShare.toFixed(2)} {internalAreaShare ? ("(Allmendefläche) + " + internalAreaShare.toFixed(2) + " m² (WG/Cluster-Fläche)") : ""}
</Text>
</Box>
<Box>
<Heading size='xs' textTransform='uppercase'>
Zahlfläche
</Heading>
<Text pt='2' fontSize='sm'>
{sizePrivate.toFixed(2)} + {commonAreaShare.toFixed(2)} (Allmendefläche) {internalAreaShare ? " + " + (internalAreaShare.toFixed(2) + " m² (WG/Cluster-Fläche)") : null}
</Text>
<Text pt={3} size='s' fontWeight='bold'>Gesamt: {totalSizeToPay.toFixed(2)} </Text>
</Box>
</Stack>
</CardBody>;
@@ -254,10 +268,7 @@ export function SelfEvaluationCard({ rent, setRent }) {
export function ResultsCard({ rent, flat, room }) {
var body = <CardBody></CardBody>
if (flat && (room || flat.wgRoomList.length === 0)) {
var totalSize = flat.sizePrivate;
if (room) {
totalSize = room.size + flat.sizeShared / flat.wgRoomList.length;
}
var totalSize = flat.calcTotalPayedArea(room)
var relativeRent = rent / totalSize;
var rangePosition = ((relativeRent - minRent) / (maxRent - minRent)) * 100;