Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split Backend Call API from the StateTopAnswerStatisticsService #5079

Merged
merged 28 commits into from
Jun 10, 2018

Conversation

brianrodri
Copy link
Contributor

This helps split up dependencies and makes the next step, adding hooks, simpler. This PR supersedes the (now closed) #5077.

@brianrodri brianrodri requested a review from seanlip June 9, 2018 23:18
@brianrodri brianrodri self-assigned this Jun 9, 2018
Copy link
Member

@seanlip seanlip left a comment

Choose a reason for hiding this comment

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

Thanks @brianrodri! This seems reasonable to me but doesn't address #5033, so I submitted another PR #5080 that complements this and can be merged in for the release.

$injector.get('StateTopAnswersStatsBackendApiService');
}));

beforeEach(inject(function($injector) {
Copy link
Member

Choose a reason for hiding this comment

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

I think you can combine this with the previous beforeEach?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

});
init: function(stateTopAnswersStatsBackendDict) {
stateTopAnswerStatsCache = {};
Object.keys(
Copy link
Member

Choose a reason for hiding this comment

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

Actually, I'm only seeing it now, but this is a bit of a strange construct. It creates a copy of the keys of the object and then iterates through them with forEach. Why not just do "for stateName in stateTopAnswersStatsBackendDict.answers"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I thought those didn't work well in JavaScript, fixed to use that!

@seanlip
Copy link
Member

seanlip commented Jun 10, 2018

Though many tests seem to be failing...

// Don't make user wait on stats to begin editing the exploration.
StateTopAnswersStatsBackendApiService.fetchStats(
$scope.explorationId
).then(StateTopAnswersStatsService.init);
Copy link
Member

Choose a reason for hiding this comment

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

Don't the new services need to be imported explicitly as dependencies?

Did you test this manually?

Copy link
Contributor Author

@brianrodri brianrodri Jun 10, 2018

Choose a reason for hiding this comment

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

Done, not yesterday was just focused on writing the logic. Did today and fixed what seems to have caused all the errors!

@codecov-io
Copy link

codecov-io commented Jun 10, 2018

Codecov Report

Merging #5079 into develop will increase coverage by 0.01%.
The diff coverage is 89.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #5079      +/-   ##
==========================================
+ Coverage    45.19%   45.2%   +0.01%     
==========================================
  Files          408     409       +1     
  Lines        23879   23889      +10     
  Branches      3860    3861       +1     
==========================================
+ Hits         10792   10800       +8     
- Misses       13087   13089       +2
Impacted Files Coverage Δ
...head/pages/exploration_editor/ExplorationEditor.js 4.86% <0%> (-0.07%) ⬇️
.../services/StateTopAnswersStatsBackendApiService.js 100% <100%> (ø)
...ead/domain/exploration/AnswerStatsObjectFactory.js 92.3% <100%> (ø)
...s/dev/head/services/StateTopAnswersStatsService.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1876e31...f57a4b3. Read the comment docs.

Copy link
Member

@seanlip seanlip left a comment

Choose a reason for hiding this comment

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

Couple small things, otherwise LGTM, thanks!

@@ -205,6 +207,13 @@ oppia.controller('ExplorationEditor', [

StateEditorTutorialFirstTimeService.init(
data.show_state_editor_tutorial_on_load, $scope.explorationId);

if (ExplorationRightsService.isPublic()) {
// Don't make user wait on stats to begin editing the exploration.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure how this comment applies to the following line (I mean, how would you fetch stats alternatively anyway)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, well I was considering loading it alongside all of the other exploration data, since this looks like the only other backend callout made in this function.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, so is the point to ensure that it's at the end? If so, maybe say that.

(Basically ... what are devs supposed to try and preserve in the future?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I've updated it. How's that?

Copy link
Member

Choose a reason for hiding this comment

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

Looks great, thanks!

@@ -324,6 +326,7 @@
<script src="{{TEMPLATE_DIR_PREFIX}}/domain/exploration/ParamSpecObjectFactory.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/domain/exploration/ParamSpecsObjectFactory.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/domain/exploration/ParamTypeObjectFactory.js"></script>
<script src="{{TEMPLATE_DIR_PREFIX}}/domain/exploration/AnswerStatsFactory.js"></script>
Copy link
Member

Choose a reason for hiding this comment

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

AnswerStatsObjectFactory.js and put it alphabetically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@brianrodri brianrodri merged commit bd1708a into oppia:develop Jun 10, 2018
@brianrodri brianrodri deleted the stas-for-real branch June 10, 2018 20:49
hoangviet1993 pushed a commit to hoangviet1993/oppia that referenced this pull request Jun 20, 2018
…a#5079)

* Split backend api calls from the service.

* Make backend API service initialize the service when exploration is first loaded.

* s/fetchExploration/fetchStats

* Don't use promise.

* Rever whitespace changes.

* Remove httpBackend from spec.

* Add isInitialized with tests.

* Make backend dict same as what's returned.

* nit: add space.

* Combine beforeEach.

* Import new backend api

* Depend on new services.

* Use for each loop.

* Respect None return values.

* Add imports to exploration_editor

* Move files

* Add answers nesting.

* Fix test to include answers wrapping.

* nit: remove extra line.

* Add whitespace again.

* Fix endswith newline lint error.

* Use Top10AnswerFrequencies calculation.

* Consistent passing of url interpolation values.

* s/AnswerStatsFactory/AnswerStatsObjectFactory

* Organize inports.

* Better worded comment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants