Skip to content

Commit ff915c2

Browse files
authored
Merge pull request #50 from MathisBurger/feature/benulli-calculations
[RELEASE v1.6.0]
2 parents bd4611e + 730daf7 commit ff915c2

14 files changed

Lines changed: 147 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ svelte => 3.44.0<br>
3636
svelte/kit => 1.0.0-next.195<br>
3737
prettier => 2.2.1<br>
3838
typescript => 4.0.0<br>
39+
compiler => ES2020

SECURITY.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
Just because MathOnWeb does not save any data about you and your user behaviour,
6+
there are no real security issues. Nevertheless, there may some risks that can have an
7+
effect. There are only security updates for the latest version of MathOnWeb. So if you are
8+
using the public instance your security level is always up to date.
9+
If you hosted the application yourself, you can validate if your current version is still secure.
10+
11+
| Version | Secure |
12+
| ------- | ------------------ |
13+
| 1.6.0 | :white_check_mark: |
14+
| 1.5.3 | :white_check_mark: |
15+
| 1.4.0 | :white_check_mark: |
16+
| 1.3.5 | :white_check_mark: |
17+
| 1.3.0 | :white_check_mark: |
18+
| 1.2.0 | :white_check_mark: |
19+
| < 1.1.2 | :x: |
20+
21+
## Reporting a Vulnerability
22+
23+
If you found a security risk, just create a new issue and explain how you found the risk
24+
and how I can recreate it. After that it will be fixed as soon as possible in the next update.
25+
You should also test this risk in different versions of the application, so I am able to specify which
26+
versions of the software are safe.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "~TODO~",
3-
"version": "0.0.1",
2+
"name": "mathonweb",
3+
"version": "1.6.0",
44
"scripts": {
55
"dev": "svelte-kit dev",
66
"build": "svelte-kit build && node src/fix-typos.js",

src/lib/defaults-provider.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Benulli } from '$src/typings/benulli';
12
import type { GeoLayerParameter, GeoLayerCoordinate } from '$src/typings/geo-layer';
23
import type { NCR } from '$src/typings/ncr';
34
import type { Triangle } from '$src/typings/triangle';
@@ -9,6 +10,7 @@ interface DefaultsProviderInterface {
910
getGeoLayerCoordinateDefault(): GeoLayerCoordinate;
1011
getDefaultTriangle(): Triangle;
1112
getDefaultNCR(): NCR;
13+
getDefaultBenulliChain(): Benulli;
1214
}
1315

1416
// Provides some functions to generate default values.
@@ -64,4 +66,12 @@ export class DefaultsProvider implements DefaultsProviderInterface {
6466
getDefaultNCR(): NCR {
6567
return { n: 0, k: 0 };
6668
}
69+
70+
/**
71+
* Returns the default benulli chain.
72+
* @returns The generated benulli chain
73+
*/
74+
getDefaultBenulliChain(): Benulli {
75+
return { n: 0, p: 0, k: 0 };
76+
}
6777
}

src/lib/solve-function.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function getVariable(func: string): string | null {
9191
* @returns The result of the eval calculation
9292
*/
9393
function calculate(func: string, variable: number, variable_letter: string): number {
94-
return eval(func.replaceAll(variable_letter, '' + variable));
94+
return eval(func.replace(variable_letter, '' + variable));
9595
}
9696

9797
export default solveFunction;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script lang="ts">
2+
import type { Benulli } from '$src/typings/benulli';
3+
export let input: Benulli;
4+
</script>
5+
6+
<div class="benulli-input">
7+
<div class="benulli-input-container">
8+
<p>n:</p>
9+
<input type="number" class="ncr-input-field" bind:value={input.n} />
10+
</div>
11+
<div class="benulli-input-container">
12+
<p>p:</p>
13+
<input type="number" class="ncr-input-field" bind:value={input.p} />
14+
</div>
15+
<div class="benulli-input-container">
16+
<p>k:</p>
17+
<input type="number" class="ncr-input-field" bind:value={input.k} />
18+
</div>
19+
</div>
20+
21+
<style lang="scss">
22+
@import '../../styles/benulli.scss';
23+
</style>

src/lib/stochastics/benulli.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { Benulli } from '$src/typings/benulli';
2+
import { calculateNCr } from './ncr-calculator';
3+
4+
/**
5+
* Calculates the result of a binomial benulli chain.
6+
*
7+
* @param chain The benulli chain that should be calculated
8+
* @returns The result of the calculation
9+
*/
10+
export function calculateBenulliChain(chain: Benulli): number {
11+
return (
12+
calculateNCr({ n: chain.n, k: chain.k }) *
13+
chain.p ** chain.k *
14+
(1 - chain.p) ** (chain.n - chain.k)
15+
);
16+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script lang="ts">
2+
import { DefaultsProvider } from '$lib/defaults-provider';
3+
4+
import { calculateBenulliChain } from '$lib/stochastics/benulli';
5+
6+
import BenulliInput from '$lib/stochastics/benulli-input.svelte';
7+
import type { Benulli } from '$src/typings/benulli';
8+
9+
let benulliData: Benulli = new DefaultsProvider().getDefaultBenulliChain();
10+
</script>
11+
12+
<div class="centered">
13+
<div class="container">
14+
<BenulliInput bind:input={benulliData} />
15+
<div class="result-form">
16+
{calculateBenulliChain(benulliData)}
17+
</div>
18+
</div>
19+
</div>
20+
21+
<style lang="scss">
22+
@import '../../styles/general.scss';
23+
</style>

src/routes/stochastics/index.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
name: $_('stochastics.ncr-calculator.title'),
1414
description: $_('stochastics.ncr-calculator.description'),
1515
route: '/stochastics/ncr-calculator'
16+
},
17+
{
18+
name: $_('stochastics.benulli-calculator.title'),
19+
description: $_('stochastics.benulli-calculator.description'),
20+
route: '/stochastics/benulli-calculator'
1621
}
1722
];
1823
</script>

src/styles/benulli.scss

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.benulli-input {
2+
display: flex;
3+
flex-direction: row;
4+
justify-content: center;
5+
align-items: center;
6+
gap: 10px;
7+
}
8+
9+
.benulli-input-container {
10+
display: flex;
11+
flex-direction: column;
12+
justify-content: flex-start;
13+
align-items: center;
14+
}
15+
16+
.benulli-input-container p {
17+
color: var(--text-color);
18+
font-size: 1.3em;
19+
}
20+
21+
.benulli-input-container input {
22+
width: 50px;
23+
height: 50px;
24+
outline: none;
25+
border: none;
26+
}

0 commit comments

Comments
 (0)