Skip to content

Commit

Permalink
572 epsilon error (#575)
Browse files Browse the repository at this point in the history
* working on new test for multiple statistics

* Show real epsilon only when unlocked, use safe_split for distributing values

* Add data-test property for Cypress test

* remove default of 0 from fixed value input field

* fixed stats fixtures

* use environment variable for ADOBE_KEY
  • Loading branch information
ekraffmiller authored Mar 24, 2022
1 parent 7c0fad7 commit 867b75e
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 169 deletions.
2 changes: 1 addition & 1 deletion client/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"defaultCommandTimeout": 120000,
"pageLoadTimeout": 120000,
"baseUrl": "http://localhost:8000",
"video": false
"video": true
}
4 changes: 2 additions & 2 deletions client/cypress/fixtures/EyeDemoData.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"statistics": [
{
"statistic": "Mean",
"variable": "eyeHeight",
"variable": "EyeHeight",
"roundedAccuracy": "1.64",
"accuracy": 1.6370121873967791,
"fixedValue": "10"
}
],
"variables": {
"eyeHeight": {
"EyeHeight": {
"name": "EyeHeight",
"label": "",
"type": "Float",
Expand Down
4 changes: 2 additions & 2 deletions client/cypress/fixtures/EyeDemoHistogram.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"statistics": [
{
"statistic": "Histogram",
"variable": "trial",
"variable": "Trial",
"roundedAccuracy": "5.39",
"accuracy": 5.393627586538017,
"fixedValue": "5"
}
],
"variables": {
"trial": {
"Trial": {
"name": "Trial",
"label": "",
"type": "Integer",
Expand Down
43 changes: 43 additions & 0 deletions client/cypress/integration/create-statistics-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,49 @@
})
cy.clearData()

})/*
it('distributes epsilon correctly ',()=> {
cy.on('uncaught:exception', (e, runnable) => {
console.log('error', e)
console.log('runnable', runnable)
return false
})
const mockDVfile = 'EyeDemoMockDV.json'
const demoDatafile = 'createStats.json'
cy.createMockDataset(mockDVfile)
cy.fixture(demoDatafile).then((demoData) => {
cy.url().should('contain', 'welcome')
cy.get('.soft_primary.rounded-lg.mt-10.pa-16').should('contain',
demoData['datasetName'])
cy.goToConfirmVariables(demoData.variables)
// select the variables we will use
cy.selectVariable(demoData.variables)
// Continue to Set Epsilon Step
cy.epsilonStep()
// Add all the statistics in the Create Statistics Step
cy.createStatistics(demoData).then(()=>{
// sum of individual epsilons should be < total epsilon
const sessionObj = JSON.parse(sessionStorage.getItem('vuex'))
const dpStatistics = sessionObj.dataset.analysisPlan.dpStatistics
const totalEpsilon = sessionObj.dataset.datasetInfo.depositorSetupInfo.epsilon
let sumEpsilon = 0;
dpStatistics.forEach(stat => { sumEpsilon += stat.epsilon})
console.log('sumEpsilon')
expect(sumEpsilon <= -1)
cy.pause()
})
})
})
*/
it('Displays correct precision', () => {
const mockDVfile = 'EyeDemoMockDV.json'
const demoDatafile = 'EyeDemoData.json'
Expand Down Expand Up @@ -75,6 +117,7 @@

})


it('Goes to the correct wizard step', () => {
cy.on('uncaught:exception', (e, runnable) => {
console.log('error', e)
Expand Down
173 changes: 36 additions & 137 deletions client/cypress/support/commands.js

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions client/src/components/MyData/ReleasePDF.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ export default {
pdfAPIReady: false,
adobeDCView: null,
viewResults: false,
// ADOBE_KEY: '34a0c926740d4ddb9758dbc6da2a4f39', // dev.dpcreator.org
ADOBE_KEY: '44937032e26b4033a840626ed0cd8e79', // demo.dpcreator.org
// ADOBE_KEY: '13c79907c6144590b17e8ef044324444', // localhost
}),
computed: {
...mapState('dataset', ['analysisPlan']),
...mapState('settings', ['vueSettings']),
style() {
if (this.viewResults) {
return "height: 1200px; width: 1000px;"
Expand All @@ -35,9 +33,9 @@ export default {
},
methods: {
handleView() {
console.log('handle view')
console.log('handle view' + this.vueSettings['VUE_APP_ADOBE_PDF_CLIENT_ID'])
this.adobeDCView = new AdobeDC.View({
clientId: this.ADOBE_KEY,
clientId: this.vueSettings['VUE_APP_ADOBE_PDF_CLIENT_ID'],
divId: "pdf-view"
});
this.adobeDCView.previewFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</v-icon
>
<v-card-title>
<h2 class="title-size-2 mb-5">{{ formTitle }}</h2>
<h2 data-test='AddStatisticDialog' class="title-size-2 mb-5">{{ formTitle }}</h2>
</v-card-title>
<v-card-text class="text--primary">
<div>
Expand Down Expand Up @@ -89,7 +89,6 @@
<div class="width50">
<v-text-field
v-model="editedItemDialog.fixedValue"
placeholder="E.g. Lorem ipsum"
background-color="soft_primary"
class="top-borders-radius width50"
data-test="Fixed value"
Expand Down Expand Up @@ -282,7 +281,7 @@ export default {
error: "",
missingValuesHandling: "insert_fixed",
handleAsFixed: true,
fixedValue: 0,
fixedValue: "",
locked: false,
accuracy: {value: null, message: null}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
<div data-test="statistic">{{ item.statistic.label }}</div>
</template>
<template v-slot:[`item.epsilon`]="{ item }">
<v-text-field
v-model="item.epsilon"
type="number"
:rules="[validateEpsilon]"
v-on:click="currentItem=item"
:disabled="!item.locked"
v-on:change="$emit('editEpsilon', item)"
<v-text-field v-if="item.locked"
v-model="item.epsilon"
type="number"
:rules="[validateEpsilon]"
v-on:click="currentItem=item"
v-on:change="$emit('editEpsilon', item)"
>
</v-text-field>
<div v-else>
{{ Number(item.epsilon).toFixed(3) }}
</div>
</template>
<template v-slot:[`item.delta`]="{ item }">
<div v-if="isDeltaStat(item)">
Expand All @@ -50,7 +52,7 @@
</template>
<template v-slot:[`item.error`]="{ item }">
<div v-if="item.accuracy">
{{ item.accuracy.value }}
{{ Number(item.accuracy.value).toPrecision(3) }}
</div>

</template>
Expand Down
24 changes: 21 additions & 3 deletions client/src/shared/createStatsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ export default {
const remaining = new Decimal(totalValue).minus(lockedValue)
let valueShare = new Decimal('0')
if (unlockedCount > 0) {
valueShare = remaining.div(unlockedCount)
valueShare = this.safeSplit(remaining, unlockedCount) //remaining.div(unlockedCount)
console.log('valueShare: ' + valueShare + "," + typeof (valueShare))
}

// Assign value shares and convert everything back from Decimal to Number
// before saving
statistics.forEach((item) => {
if (this.statisticUsesValue(property, item.statistic)) {
if (!item.locked) {
item[property] = valueShare.toNumber()
item[property] = valueShare
} else {
if (typeof (item[property]) == Decimal) {
item[property] = item[property].toNumber()
Expand All @@ -85,6 +86,23 @@ export default {


},
safeSplit(budget, k) {
// algorithm from Micheal Shoemate to ensure we don't exceed the total budget
let is_x_gte_kv = (x, k, v) =>
x >= Array(k).fill().reduce((s, _) => s + v, 0)
let split_budget = (x, k) => {
// preserve symmetry if possible
if (is_x_gte_kv(x, k, x / k)) return x / k

// try increasingly large offsets until passes
for (pow of Array(20).keys()) {
// candidate value v
let v = (x - Math.pow(10, pow - 20)) / k
if (is_x_gte_kv(x, k, v)) return v
}
}
return split_budget(budget, k)
},

// Returns Promise json object:
// valid: true/false
Expand All @@ -93,7 +111,7 @@ export default {
let returnObj = {valid: true, data: null}
return release.validate(analysisPlanId, tempStats)
.then((resp) => {
// console.log('releaseValidation, validate response: ' + JSON.stringify(resp))
// console.log('releaseValidation, validate response: ' + JSON.stringify(resp))
returnObj.data = resp.data
resp.data.forEach((item, index) => {
if (item.valid !== true) {
Expand Down
9 changes: 1 addition & 8 deletions client/src/views/WizardSteps/CreateStatistics.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div id="create-statistics-page">
<h1 class="title-size-1">Create Statistics</h1>
<h1 data-test="Create Statistics Title" class="title-size-1">Create Statistics</h1>
<p>
{{
$t('create statistics.statistics intro')
Expand Down Expand Up @@ -167,12 +167,6 @@ export default {
} else {
this.statistics = []
}
this.statistics.forEach((stat) => {
stat.epsilon = Number(stat.epsilon).toFixed(3)
if (stat.error !== null) {
stat.error = (Number(stat.error)).toPrecision(3)
}
})
if (this.getDepositorSetupInfo.epsilon == null) {
this.epsilon = this.getDepositorSetupInfo.defaultEpsilon
} else {
Expand Down Expand Up @@ -260,7 +254,6 @@ export default {
const accuracy = validateResults.data[i].accuracy
this.statistics[i].accuracy.value = Number(accuracy.value).toPrecision(3)
this.statistics[i].accuracy.message = accuracy.message
this.statistics[i].epsilon = Number(this.statistics[i].epsilon).toFixed(3)
// this assigment below didn't work! Can't change the object reference, need to change the values
// this.statistics[i] = Object.assign({}, this.statistics[i], { accuracy })
}
Expand Down

0 comments on commit 867b75e

Please sign in to comment.