Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
rhbz953734 - fix statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed May 22, 2013
1 parent 3f94bc4 commit b34fd96
Showing 1 changed file with 38 additions and 3 deletions.
Expand Up @@ -345,11 +345,16 @@ public void onSuccess(GetDocumentStatsResult result)

if(currentMsgStats == null)
{
Log.info("adding to projectStats");
logStatistics(docInfo.getId() + " doc ", msgStats);
projectStats.addStats(msgStats);
}
else
{
// logStatistics(docInfo.getId() + " current msg stats before add", currentMsgStats);
currentMsgStats.add(msgStats);
// logStatistics(docInfo.getId() + " from docInfo ", msgStats);
// logStatistics(docInfo.getId() + " current msg stats after add", currentMsgStats);
}

TranslationStatistics wordStats = docInfo.getStats().getStats(localeId.getId(), StatUnit.WORD);
Expand Down Expand Up @@ -483,6 +488,7 @@ public void onDocumentSelected(DocumentSelectionEvent event)
public void onTransUnitUpdated(TransUnitUpdatedEvent event)
{
TransUnitUpdateInfo updateInfo = event.getUpdateInfo();
Log.info("********** updated Info:" + updateInfo);
// update stats for containing document
DocumentInfo updatedDoc = getDocumentInfo(updateInfo.getDocumentId());
if (updatedDoc.getStats() != null)
Expand All @@ -502,8 +508,23 @@ public void onTransUnitUpdated(TransUnitUpdatedEvent event)
}

// update project stats, forward to AppPresenter
adjustStats(projectStats, updateInfo);
eventBus.fireEvent(new ProjectStatsUpdatedEvent(projectStats));
// logStatistics("before adjust project stats", projectStats.getStats(localeId.getId(), StatUnit.MESSAGE));
// FIXME rhbz953734 - with this line statistics will be double adjusted. What's the use of projectStats? do we still need it?
// adjustStats(projectStats, updateInfo);
// logStatistics("after adjust project stats", projectStats.getStats(localeId.getId(), StatUnit.MESSAGE));
// eventBus.fireEvent(new ProjectStatsUpdatedEvent(projectStats));
}

private static void logStatistics(String msg, TranslationStatistics statistics)
{
String string = com.google.common.base.Objects.toStringHelper(statistics).
add("unit", statistics.getUnit()).
add("approved", statistics.getApproved()).
add("draft", statistics.getDraft()).
add("new", statistics.getUntranslated()).
// add("locale", statistics.getLocale()).
toString();
Log.info(msg + " statistics: " + string);
}

private void updateLastTranslatedInfo(DocumentInfo doc, TransUnit updatedTransUnit)
Expand All @@ -519,9 +540,23 @@ private void adjustStats(CommonContainerTranslationStatistics stats, TransUnitUp
{
TranslationStatistics msgStatistic = stats.getStats(localeId.getId(), StatUnit.MESSAGE);
TranslationStatistics wordStatistic = stats.getStats(localeId.getId(), StatUnit.WORD);


// Log.info("***** msgStats before update:");
// Log.info("***** approved:" + msgStatistic.getApproved());
// Log.info("***** draft:" + msgStatistic.getDraft());
// Log.info("***** untranslated:" + msgStatistic.getUntranslated());
// Log.info("***** previous state:" + updateInfo.getPreviousState());
// Log.info("***** new state:" + updateInfo.getTransUnit().getStatus());
logStatistics("before adjust", msgStatistic);
msgStatistic.decrement(updateInfo.getPreviousState(), 1);
msgStatistic.increment(updateInfo.getTransUnit().getStatus(), 1);
logStatistics("after adjust", msgStatistic);

// Log.info("***** msgStats after update:");
// Log.info("***** approved:" + msgStatistic.getApproved());
// Log.info("***** draft:" + msgStatistic.getDraft());
// Log.info("***** untranslated:" + msgStatistic.getUntranslated());

wordStatistic.decrement(updateInfo.getPreviousState(), updateInfo.getSourceWordCount());
wordStatistic.increment(updateInfo.getTransUnit().getStatus(), updateInfo.getSourceWordCount());
}
Expand Down

0 comments on commit b34fd96

Please sign in to comment.