Skip to content

Commit

Permalink
Merge 534b038 into d26773d
Browse files Browse the repository at this point in the history
  • Loading branch information
slobodan-ilic committed May 22, 2019
2 parents d26773d + 534b038 commit b537227
Show file tree
Hide file tree
Showing 3 changed files with 311 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ def _load_to_cache(self, fixture_name):

CR = LazyCubeResponseLoader(".") # ---mnemonic: CR = 'cube-response'---
SM = LazyCubeResponseLoader("./scale_means")
SC = LazyCubeResponseLoader("./scorecards")
285 changes: 285 additions & 0 deletions tests/fixtures/scorecards/sandwiches-by-mike.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
{
"element": "shoji:view",
"self": "/api/cube/etc",
"value": {
"query": {
"measures": {
"count": {
"function": "cube_count",
"args": []
}
},
"dimensions": [
{
"each": "/api/variables/92137844840d4a82b3a298e64e2a995d/"
},
{
"function": "as_selected",
"args": [
{
"variable": "/api/variables/92137844840d4a82b3a298e64e2a995d/"
}
]
},
{
"function": "fuse"
}
],
"weight": null
},
"query_environment": {
"filter": []
},
"result": {
"dimensions": [
{
"derived": true,
"references": {
"alias": "test"
},
"type": {
"subtype": {
"class": "variable"
},
"elements": [
{
"id": 1,
"value": {
"derived": false,
"references": {
"alias": "10230#####",
"name": "Overall liking of sandwich",
"view": {
"show_counts": false,
"include_missing": false,
"column_width": null
}
},
"id": "1"
},
"missing": false
},
{
"id": 2,
"value": {
"derived": false,
"references": {
"alias": "10231#####",
"name": "Overall taste of sandwich",
"view": {
"show_counts": false,
"include_missing": false,
"column_width": null
}
},
"id": "2"
},
"missing": false
},
{
"id": 3,
"value": {
"derived": false,
"references": {
"alias": "10232#####",
"name": "Overall appearance of sandwich (based on full sandwich display)",
"view": {
"show_counts": false,
"include_missing": false,
"column_width": null
}
},
"id": "3"
},
"missing": false
},
{
"id": 4,
"value": {
"derived": false,
"references": {
"alias": "10234#####",
"name": "Overall liking of the spinach wrap itself",
"view": {
"show_counts": false,
"include_missing": false,
"column_width": null
}
},
"id": "4"
},
"missing": false
},
{
"id": 5,
"value": {
"derived": false,
"references": {
"alias": "20233###",
"name": "Overall liking of the bread itself",
"view": {
"show_counts": false,
"include_missing": false,
"column_width": null
}
},
"id": "4"
},
"missing": false
}
],
"class": "enum"
}
},
{
"derived": true,
"references": {
"alias": "test",
"subreferences": {}
},
"type": {
"ordinal": false,
"class": "categorical",
"categories": [
{
"numeric_value": 1,
"selected": true,
"id": 1,
"missing": false,
"name": "Selected"
},
{
"numeric_value": 0,
"id": 0,
"name": "Other",
"missing": false
},
{
"numeric_value": null,
"id": -1,
"name": "No Data",
"missing": true
}
]
}
},
{
"derived": true,
"references": {
"alias": "test"
},
"type": {
"class": "enum",
"subtype": {
"class": "variable"
},
"elements": [
{
"id": 1,
"name": "wrap",
"description": "spinach wrap"
},
{
"id": 2,
"name": "sandwich",
"description": "sandwich on bread"
}
]
}
}
],
"missing": 2,
"measures": {
"count": {
"data": [
49,
37,
53,
63,
2,
4,
42,
40,
60,
60,
2,
4,
35,
45,
67,
55,
2,
4,
40,
0,
62,
0,
2,
104,
0,
41,
0,
59,
104,
4
],
"n_missing": 2,
"metadata": {
"references": {},
"derived": true,
"type": {
"integer": true,
"missing_rules": {},
"missing_reasons": {
"No Data": -1
},
"class": "numeric"
}
}
}
},
"n": 104,
"unfiltered": {
"unweighted_n": 104,
"weighted_n": 104
},
"filtered": {
"unweighted_n": 104,
"weighted_n": 104
},
"counts": [
49,
37,
53,
63,
2,
4,
42,
40,
60,
60,
2,
4,
35,
45,
67,
55,
2,
4,
40,
0,
62,
0,
2,
104,
0,
41,
0,
59,
104,
4
],
"element": "crunch:cube"
}
}
}
25 changes: 25 additions & 0 deletions tests/integration/test_scorecards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# encoding: utf-8

"""Integration tests for scorecards."""

import numpy as np

from cr.cube.crunch_cube import CrunchCube
from cr.cube.slices import FrozenSlice

from ..fixtures import SC # ---mnemonic: SC = 'scorecards'---


class DescribeIntegratedScoreCard(object):
def it_loads_from_simple_scorecard_json(self):
slice_ = FrozenSlice(CrunchCube(SC.SANDWICHES_BY_MIKE))
np.testing.assert_almost_equal(
slice_.column_percentages,
[
[48.03921569, 37.0],
[41.17647059, 40.0],
[34.31372549, 45.0],
[39.21568627, np.nan],
[np.nan, 41.0],
],
)

0 comments on commit b537227

Please sign in to comment.