Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Feature/ego charts #255

Merged
merged 5 commits into from
Aug 21, 2019
Merged

Feature/ego charts #255

merged 5 commits into from
Aug 21, 2019

Conversation

rebeccamadsen
Copy link
Contributor

Resolves #252. This adds both ego and edge ordinal/categorical variables to the server overview screen, and to the settings screen to toggle which ones display.

It also fixes a bug where the counts were incorrect if you had two variables of the same name within the same entity (e.g. node: person with variable: catVar, and node: venue with variable: catVar).

@rebeccamadsen rebeccamadsen requested review from wwqrd and jthrilly August 1, 2019 18:42
@wwqrd
Copy link
Contributor

wwqrd commented Aug 6, 2019

I'm seeing the ego variables showing up in the settings panel, but getting nothing on the overview screen?

@wwqrd
Copy link
Contributor

wwqrd commented Aug 6, 2019

I'm seeing the ego variables showing up in the settings panel, but getting nothing on the overview screen?

Actually, I can't reproduce this. Closing the app and restarting seems to have fixed it, and now it works as expected. I wonder if it was just an issue with rehydrating the app state?

Copy link
Contributor

@wwqrd wwqrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works great 👍

I have a few questions about the code which may be nonsensical, hopefully useful.

One thing I wondered looking at these changes is if we should try to model the ego in the network as 'ego.ego' to make a lot of these transformations unified (would apply to other apps too) e.g.:

const network = {
  node: {
    person: { /* person config */ },
  },
  ego: {
    ego: { /* ego config */ },
  },
  // ...
}

api.get('/protocols/:id/reports/option_buckets', (req, res, next) => {
const { variableNames = '', entityName = 'node' } = req.query;
this.reportDb.optionValueBuckets(req.params.id, variableNames.split(','), entityName)
api.post('/protocols/:id/reports/option_buckets', (req, res, next) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why switch to post? Isn't the API currently RESTful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we were sending an array of variable names as part of the "get" request (e.g. [var1, var2, var3]) and assuming they were node variables and that types had no overlapping variables. I needed to separate those variables into ego variable, edge variables with types, and node variables with types (e.g. nodes: { type1: [var1, var2, var3], type2: [var1] }), and I couldn't send that complex of data with "get" as far as I knew.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay seems like a good pragmatic decision. I think we should add a comment for posterity?

@@ -9,8 +9,12 @@ import { mockProtocol } from '../../../../../config/jest/setupTestEnv';

jest.mock('../../../utils/adminApiClient', () => {
function MockApiClient() {}
MockApiClient.prototype.get = jest.fn().mockResolvedValue({
buckets: { person: { distributionVariable: { 1: 4, 2: 5 } } },
MockApiClient.prototype.post = jest.fn().mockResolvedValue({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts on switching over to using jest snapshots? I think it makes these kinds of tests simpler to manage, at the expense of requiring more scrutiny for snapshot updates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really mind one way or another. I don't think it is updated that often?

if (!isDistributionVariable(def) || excludedSectionVariables.includes(def.name)) {
return;
}
const data = buckets[entityType] && buckets[entityType][variableName];
const data = entityKey === 'ego' ? buckets && buckets[variableName] : buckets[entityType] && buckets[entityType][variableName];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about breaking this out into a couple of steps, maybe like:

const dataPath = entityKey === 'ego' ? [variableName] : [entityType, variableName];
const data = get(buckets, dataPath);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion. I'll make this update.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this update, and added a comment. I think that voids your review approval... :)

@@ -57,6 +60,15 @@ const shapeBucketData = (transposedNodeCodebook, buckets, excludedChartVariables
return acc;
}, []);

const shapeBucketData = (codebook, buckets, excludedChartVariables) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make 'ego' appear as a type? Could that conflict unexpectedly with a node with the same 'type' name?

Should we add a function to describe this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does make ego appear as a type. It wouldn't conflict because it is embedded within the entity as well (basically ego: { ego: [var1, var2] })

@rebeccamadsen
Copy link
Contributor Author

One thing I wondered looking at these changes is if we should try to model the ego in the network as 'ego.ego' to make a lot of these transformations unified (would apply to other apps too)

Yeah, I've wondered the same thing in other apps as well as here. Though ego doesn't really have a type, it could simplify things to structure it like it did. Is it just that is makes no logical sense to have a type for ego, or are there some things that are better because we have no ego type? I mean, it really does make no logical sense to have an ego type. But this is not the first time the code work arounds were kind of ridiculous because there is no ego type.

wwqrd
wwqrd previously approved these changes Aug 7, 2019
Copy link
Contributor

@wwqrd wwqrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I've wondered the same thing in other apps as well as here. Though ego doesn't really have a type, it could simplify things to structure it like it did. Is it just that is makes no logical sense to have a type for ego, or are there some things that are better because we have no ego type? I mean, it really does make no logical sense to have an ego type. But this is not the first time the code work arounds were kind of ridiculous because there is no ego type.

I think it's a semantic choice, egos just don't have a type. At this point the protocol API is probably not going to change, but we could convert it when loading into state, or at least bare this pattern in mind when we need to reuse functions.

@jthrilly
Copy link
Member

jthrilly commented Aug 21, 2019

I'm afraid I much prefer the duplication of code caused by ego not having a type, to changing the model to ego.ego or similar. I prefer the data model to be conceptually "pure" and accepting complexity in the app logic, rather than the other way around. Data interoperability is going to be lessened by polluting the model (by this I mean that our data model is now effectively a normalized graph model), and the schema would also (logically speaking) need to be updated.

Copy link
Member

@jthrilly jthrilly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Also fixes a crash on the settings screen I was seeing in the previous version. Bonus!

@jthrilly jthrilly merged commit 78d5bc8 into master Aug 21, 2019
@rebeccamadsen rebeccamadsen deleted the feature/ego-charts branch August 21, 2019 13:53
jthrilly added a commit that referenced this pull request Jul 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

There are no charts for Ego variables on the overview screen
3 participants