Skip to content

Commit

Permalink
Refactor spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
huulbaek committed Nov 2, 2023
1 parent 8f3b6c2 commit 43861a1
Show file tree
Hide file tree
Showing 22 changed files with 210 additions and 89 deletions.
9 changes: 5 additions & 4 deletions src/calculations/calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export default class Calculator {
#addCustomSpace (name: string, result: ISpaceResult): ISpace {
return {
name,
className: 'Dummy',
result,
constants: {
areaPerRole: 0,
Expand Down Expand Up @@ -344,7 +345,7 @@ export default class Calculator {
*/
#calculateSpaceFirstRun (space: ISpace): ISpaceResult {
const Space = getSpace(space.name)
const spaceCalculation: ISpaceCalculation = new Space(space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const spaceCalculation: ISpaceCalculation = new Space(this.variables, this.config, this.customSpaceConstants, this.customConstants, space)
return {
areaExclCompensation: spaceCalculation.calculateAreaExclCompensation(),
employeesPerWorkplaceTypeUnadjusted: spaceCalculation.calculateEmployeesPerWorkplaceTypeUnadjusted(),
Expand All @@ -358,7 +359,7 @@ export default class Calculator {
*/
#calculateSpaceSecondRun (space: ISpace): ISpaceResult {
const Space = getSpace(space.name)
const spaceCalculation: ISpaceCalculation = new Space(space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const spaceCalculation: ISpaceCalculation = new Space(this.variables, this.config, this.customSpaceConstants, this.customConstants, space)
return {
notAdjustedAddonArea: spaceCalculation.calculateNotAdjustedAddonArea(this.totalWorkplaceArea, this.totalCompensationArea),
}
Expand All @@ -371,7 +372,7 @@ export default class Calculator {
*/
#calculateSpaceThirdRun (space: ISpace): ISpaceResult {
const Space = getSpace(space.name)
const spaceCalculation: ISpaceCalculation = new Space(space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const spaceCalculation: ISpaceCalculation = new Space(this.variables, this.config, this.customSpaceConstants, this.customConstants, space)
return {
notAdjustedAddonPart: spaceCalculation.calculateNotAdjustedAddonPart(this.totalWorkplaceArea, this.totalCompensationArea),
adjustedAddonArea: spaceCalculation.calculateAdjustedAddonArea(this.totalWorkplaceArea, this.totalCompensationArea, this.totalUnadjustedArea),
Expand All @@ -387,7 +388,7 @@ export default class Calculator {
*/
#calculateSpaceFourthRun (space: ISpace): ISpaceResult {
const Space = getSpace(space.name)
const spaceCalculation: ISpaceCalculation = new Space(space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const spaceCalculation: ISpaceCalculation = new Space(this.variables, this.config, this.customSpaceConstants, this.customConstants, space)
return {
adjustedAreaInclCompensationWithAdjustmentAndCompensation: spaceCalculation.calculateAdjustedAreaInclCompensationWithAdjustmentAndCompensation(),
numberOfRooms: spaceCalculation.calculateNumberOfRooms(),
Expand Down
22 changes: 22 additions & 0 deletions src/calculations/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ISpace } from './interfaces/space'

/**
* This function returns the space information from an array of space spaces. Recursively until found.
* @param {string} spaceClassName - The name of the space
* @param {ISpace[]} spaces - The array of spaces
* @returns {ISpace|void}
*/
const findSpace = (spaceClassName: string, spaces: ISpace[]): ISpace|void => {
for (const space of spaces) {
if (space.className === spaceClassName) {
return space
} else if (space.spaces) {
const foundSpace = findSpace(spaceClassName, space.spaces)
if (foundSpace) {
return foundSpace
}
}
}
}

export { findSpace }
1 change: 1 addition & 0 deletions src/calculations/interfaces/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface ISpace {
result: ISpaceResult // The result of the calculations for this space
shouldCalculateCorridor?: boolean // Whether to calculate the corridor area needed for this space
shouldCalculateInnerwalls?: boolean // Whether to calculate the inner walls area needed for this space
className: string // The name of the class of this space
}
4 changes: 2 additions & 2 deletions src/calculations/spaces/common area/lobby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default class Lobby extends MainSpace {
calculateAreaExclCompensation = (): number => {
if (this.variables.accessToAuditorium || this.variables.accessToCourseSpace) {
// Get the area of the auditorium and the course space
const auditorium = new Auditorium(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const course = new Course(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const auditorium = new Auditorium(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const course = new Course(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const areaPerPerson = this.spaceConstants.areaPerRole / this.spaceConstants.personsPerType

const x = auditorium.calculateAreaExclCompensation() / areaPerPerson
Expand Down
3 changes: 2 additions & 1 deletion src/calculations/spaces/dummy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default class Dummy extends MainSpace {
constructor(variables: IVariable, config: IConfig) {
const space: ISpace = {
name: "dummy",
className: "Dummy",
result: {},
constants: {
seatPersonRoom: "person",
Expand All @@ -22,7 +23,7 @@ export default class Dummy extends MainSpace {
adhereToGovernmentMinimum: false
}
}
super(space, variables, config)
super(variables, config)
this.name = this.space.name
this.space = space
this.spaceConstants = space.constants
Expand Down
10 changes: 7 additions & 3 deletions src/calculations/spaces/main_space_class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ISpaceConstant } from '../interfaces/space_constant'
import { ISpaceCalculation } from '../interfaces/space_calculation'
import { IConstant } from '../interfaces/constant'
import { IVariable } from '../interfaces/variable'
import { findSpace } from '../helpers'

type TCustomSpaceConstants = {[key:string]:ISpaceConstant}

Expand All @@ -22,13 +23,16 @@ export default class MainSpace implements ISpaceCalculation {

/**
* Constructor for the main space class.
* @param {Ispace} space - The space to calculate
* @param {Ispace|string} space - The space to calculate
* @param {IVariable} variables - The variables to use
* @param {IConfig} config - The config to use
* @param {TCustomSpaceConstants} [customSpaceConstants] - Custom space constants, optional
* @param {IConstant} [customConstants] - Custom constants, optional
*/
constructor(space: ISpace, variables: IVariable, config: IConfig, customSpaceConstants?: TCustomSpaceConstants, customConstants?: IConstant) {
constructor(variables: IVariable, config: IConfig, customSpaceConstants?: TCustomSpaceConstants, customConstants?: IConstant, space?: ISpace) {
if (!space) {
space = findSpace(this.constructor.name, config.spaces)!
}
this.name = space.name
this.space = space
this.spaceConstants = space.constants
Expand Down Expand Up @@ -153,7 +157,7 @@ export default class MainSpace implements ISpaceCalculation {
*/
calculateNumberOfRooms (): number {
if (this.spaceConstants.shouldCalculateNumberOfRooms) {
return Math.ceil(this.space.result.adjustedAreaInclCompensation! / this.spaceConstants.minimumSquareMeters!)
return Math.floor(this.space.result.adjustedAreaInclCompensation! / this.spaceConstants.minimumSquareMeters!)
}
return 0
}
Expand Down
19 changes: 12 additions & 7 deletions src/calculations/spaces/shared area/meetingroom_large.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Landscape from '../work related area/landscape'
import Projectroom from '../work related area/projectroom'
import Focusroom from '../work related area/focusroom'
import Quietzone from '../work related area/quietzone'
import SharedSmallMeetingroom from './meetingroom_small'
import SharedMediumMeetingroom from './meetingroom_medium'

export default class SharedLargeMeetingroom extends MainSpace {
/**
Expand All @@ -21,14 +23,17 @@ export default class SharedLargeMeetingroom extends MainSpace {
*/
calculateAreaExclCompensation = (): number => {
if (this.variables.accessToCoworking) {
const workDockin = new WorkDockin(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const cellOffice = new CellOffice(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const landscape = new Landscape(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const projectroom = new Projectroom(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const focusroom = new Focusroom(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const quietzone = new Quietzone(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const workDockin = new WorkDockin(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const cellOffice = new CellOffice(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const landscape = new Landscape(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const projectroom = new Projectroom(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const focusroom = new Focusroom(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const quietzone = new Quietzone(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const addedPeakAreaSum = workDockin.calculateEmployeesPerWorkplaceTypeUnadjusted() + cellOffice.calculateEmployeesPerWorkplaceTypeUnadjusted() + landscape.calculateEmployeesPerWorkplaceTypeUnadjusted() + projectroom.calculateEmployeesPerWorkplaceTypeUnadjusted() + focusroom.calculateEmployeesPerWorkplaceTypeUnadjusted() + quietzone.calculateEmployeesPerWorkplaceTypeUnadjusted()
return addedPeakAreaSum * this.areaPerPersonExcludingCorridor() * this.variables.coworkingShare + this.addedPeakArea()
const sharedSmallMeetingroom = new SharedSmallMeetingroom(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const sharedMediumMeetingroom = new SharedMediumMeetingroom(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const areaPerPersonExcludingCorridorSum = sharedSmallMeetingroom.areaPerPersonExcludingCorridor() + sharedMediumMeetingroom.areaPerPersonExcludingCorridor() + this.areaPerPersonExcludingCorridor()
return this.variables.largeMeetingroomShare * addedPeakAreaSum * areaPerPersonExcludingCorridorSum * this.variables.coworkingShare + this.addedPeakArea()
}
return 0
}
Expand Down
19 changes: 12 additions & 7 deletions src/calculations/spaces/shared area/meetingroom_medium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Landscape from '../work related area/landscape'
import Projectroom from '../work related area/projectroom'
import Focusroom from '../work related area/focusroom'
import Quietzone from '../work related area/quietzone'
import SharedSmallMeetingroom from './meetingroom_small'
import SharedLargeMeetingroom from './meetingroom_large'

export default class SharedMediumMeetingroom extends MainSpace {
/**
Expand All @@ -21,14 +23,17 @@ export default class SharedMediumMeetingroom extends MainSpace {
*/
calculateAreaExclCompensation = (): number => {
if (this.variables.accessToCoworking) {
const workDockin = new WorkDockin(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const cellOffice = new CellOffice(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const landscape = new Landscape(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const projectroom = new Projectroom(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const focusroom = new Focusroom(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const quietzone = new Quietzone(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const workDockin = new WorkDockin(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const cellOffice = new CellOffice(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const landscape = new Landscape(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const projectroom = new Projectroom(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const focusroom = new Focusroom(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const quietzone = new Quietzone(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const addedPeakAreaSum = workDockin.calculateEmployeesPerWorkplaceTypeUnadjusted() + cellOffice.calculateEmployeesPerWorkplaceTypeUnadjusted() + landscape.calculateEmployeesPerWorkplaceTypeUnadjusted() + projectroom.calculateEmployeesPerWorkplaceTypeUnadjusted() + focusroom.calculateEmployeesPerWorkplaceTypeUnadjusted() + quietzone.calculateEmployeesPerWorkplaceTypeUnadjusted()
return addedPeakAreaSum * this.areaPerPersonExcludingCorridor() * this.variables.coworkingShare + this.addedPeakArea()
const sharedSmallMeetingroom = new SharedSmallMeetingroom(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const sharedLargeMeetingroom = new SharedLargeMeetingroom(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const areaPerPersonExcludingCorridorSum = sharedSmallMeetingroom.areaPerPersonExcludingCorridor() + sharedLargeMeetingroom.areaPerPersonExcludingCorridor() + this.areaPerPersonExcludingCorridor()
return this.variables.mediumMeetingroomShare * addedPeakAreaSum * areaPerPersonExcludingCorridorSum * this.variables.coworkingShare + this.addedPeakArea()
}
return 0
}
Expand Down
19 changes: 12 additions & 7 deletions src/calculations/spaces/shared area/meetingroom_small.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Landscape from '../work related area/landscape'
import Projectroom from '../work related area/projectroom'
import Focusroom from '../work related area/focusroom'
import Quietzone from '../work related area/quietzone'
import SharedMediumMeetingroom from './meetingroom_medium'
import SharedLargeMeetingroom from './meetingroom_large'

export default class SharedSmallMeetingroom extends MainSpace {
/**
Expand All @@ -21,14 +23,17 @@ export default class SharedSmallMeetingroom extends MainSpace {
*/
calculateAreaExclCompensation = (): number => {
if (this.variables.accessToCoworking) {
const workDockin = new WorkDockin(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const cellOffice = new CellOffice(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const landscape = new Landscape(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const projectroom = new Projectroom(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const focusroom = new Focusroom(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const quietzone = new Quietzone(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const workDockin = new WorkDockin(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const cellOffice = new CellOffice(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const landscape = new Landscape(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const projectroom = new Projectroom(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const focusroom = new Focusroom(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const quietzone = new Quietzone(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const addedPeakAreaSum = workDockin.calculateEmployeesPerWorkplaceTypeUnadjusted() + cellOffice.calculateEmployeesPerWorkplaceTypeUnadjusted() + landscape.calculateEmployeesPerWorkplaceTypeUnadjusted() + projectroom.calculateEmployeesPerWorkplaceTypeUnadjusted() + focusroom.calculateEmployeesPerWorkplaceTypeUnadjusted() + quietzone.calculateEmployeesPerWorkplaceTypeUnadjusted()
return addedPeakAreaSum * this.areaPerPersonExcludingCorridor() * this.variables.coworkingShare + this.addedPeakArea()
const sharedMediumMeetingroom = new SharedMediumMeetingroom(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const sharedLargeMeetingroom = new SharedLargeMeetingroom(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const areaPerPersonExcludingCorridorSum = sharedMediumMeetingroom.areaPerPersonExcludingCorridor() + sharedLargeMeetingroom.areaPerPersonExcludingCorridor() + this.areaPerPersonExcludingCorridor()
return this.variables.smallMeetingroomShare * addedPeakAreaSum * areaPerPersonExcludingCorridorSum * this.variables.coworkingShare + this.addedPeakArea()
}
return 0
}
Expand Down
12 changes: 6 additions & 6 deletions src/calculations/spaces/shared area/multiroom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export default class SharedMultiroom extends MainSpace {
calculateAreaExclCompensation = (): number => {
if (this.variables.accessToCoworking) {
//=SUM((AP4:AP10)*AR26*AQ26)+(AB26)
const workDockin = new WorkDockin(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const cellOffice = new CellOffice(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const landscape = new Landscape(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const projectroom = new Projectroom(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const focusroom = new Focusroom(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const quietzone = new Quietzone(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const workDockin = new WorkDockin(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const cellOffice = new CellOffice(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const landscape = new Landscape(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const projectroom = new Projectroom(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const focusroom = new Focusroom(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const quietzone = new Quietzone(this.variables, this.config, this.customSpaceConstants, this.customConstants)
const addedPeakAreaSum = workDockin.calculateEmployeesPerWorkplaceTypeUnadjusted() + cellOffice.calculateEmployeesPerWorkplaceTypeUnadjusted() + landscape.calculateEmployeesPerWorkplaceTypeUnadjusted() + projectroom.calculateEmployeesPerWorkplaceTypeUnadjusted() + focusroom.calculateEmployeesPerWorkplaceTypeUnadjusted() + quietzone.calculateEmployeesPerWorkplaceTypeUnadjusted()
return addedPeakAreaSum * this.areaPerPersonExcludingCorridor() * this.sharePerWorkspaceType() + this.addedPeakArea()
}
Expand Down
2 changes: 1 addition & 1 deletion src/calculations/spaces/work related area/dockin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class WorkDockin extends MainSpace {
*/
sharePerWorkspaceType = (): number => {
// We need the shared dock in share for the calculation of the work dock in share
const sharedDockin = new SharedDockin(this.space, this.variables, this.config, this.customSpaceConstants, this.customConstants)
const sharedDockin = new SharedDockin(this.variables, this.config, this.customSpaceConstants, this.customConstants)
return this.variables.dockinShare - sharedDockin.sharePerWorkspaceType()
}

Expand Down
Loading

0 comments on commit 43861a1

Please sign in to comment.