10 package de.uni_hamburg.corpora;
13 import java.text.MessageFormat;
14 import java.text.SimpleDateFormat;
15 import java.util.Collection;
17 import java.util.HashMap;
18 import java.util.ArrayList;
19 import java.util.Date;
20 import org.jdom.JDOMException;
50 private Map<String, Collection<ReportItem>> statistics;
55 private Collection<ReportItem> getOrCreateStatistic(String statId) {
56 if (!statistics.containsKey(statId)) {
57 statistics.put(statId,
new ArrayList<ReportItem>());
59 return statistics.get(statId);
66 statistics =
new HashMap<String, Collection<ReportItem>>();
74 for (Map.Entry<String, Collection<ReportItem>> kv
75 : sr.statistics.entrySet()) {
76 if (statistics.containsKey(kv.getKey())) {
77 Collection<ReportItem> c
78 = statistics.get(kv.getKey());
79 c.addAll(kv.getValue());
80 statistics.put(kv.getKey(), c);
82 statistics.put(kv.getKey(), kv.getValue());
95 Collection<ReportItem> stat = getOrCreateStatistic(statId);
112 Collection<ReportItem> stat = getOrCreateStatistic(statId);
122 public void addCritical(String statId, String description, String extraBlah) {
129 public void addCritical(String statId, Throwable e, String description, String extrablah) {
131 +
"..." + e.getStackTrace()[0]);
139 public void addCritical(String statId, Throwable e, String description) {
140 addCritical(statId, description + e.getStackTrace()[0]);
147 Collection<ReportItem> stat = getOrCreateStatistic(statId);
149 cd.
getURL().toString(), description, statId));
156 Collection<ReportItem> stat = getOrCreateStatistic(statId);
158 cd.
getURL().toString(), description, statId));
165 Collection<ReportItem> stat = getOrCreateStatistic(statId);
175 public void addWarning(String statId, String description, String extraBlah) {
182 public void addWarning(String statId, Throwable e, String description, String extrablah) {
183 addWarning(statId, description +
"::" + extrablah
184 +
"..." + e.getStackTrace()[0]);
191 Collection<ReportItem> stat = getOrCreateStatistic(statId);
193 cd.
getURL().toString(), description, statId));
200 Collection<ReportItem> stat = getOrCreateStatistic(statId);
209 Collection<ReportItem> stat = getOrCreateStatistic(statId);
211 cd.
getURL().toString(), description, statId));
218 Collection<ReportItem> stat = getOrCreateStatistic(statId);
227 public void addCorrect(String statId, String filename, String description) {
228 Collection<ReportItem> stat = getOrCreateStatistic(statId);
230 description, statId));
237 Collection<ReportItem> stat = getOrCreateStatistic(statId);
239 cd.
getURL().toString(), description, statId));
245 public void addNote(String statId, String description) {
246 Collection<ReportItem> stat = getOrCreateStatistic(statId);
254 public void addNote(String statId, Throwable e, String description) {
255 addNote(statId, description +
"..." + e.getStackTrace()[0]);
261 public void addNote(String statId, Throwable e, String description, String extrablah) {
262 addNote(statId, description +
"::" + extrablah
263 +
"..." + e.getStackTrace()[0]);
269 public void addNote(String statId, String description, String extraBlah) {
270 addNote(statId, description +
"::" + extraBlah);
277 Collection<ReportItem> stat = getOrCreateStatistic(statId);
279 cd.
getURL().toString(), description, statId));
297 public void addException(String statId, Throwable e, String description) {
298 Collection<ReportItem> stat = getOrCreateStatistic(statId);
306 public void addException(String statId, Throwable e, String description,
308 addException(statId, e, description +
"\n\t" + extrablah);
315 Collection<ReportItem> stat = getOrCreateStatistic(statId);
317 e, cd.
getURL().toString(), description));
328 Collection<ReportItem> stats = statistics.get(statId);
332 }
else if (s.isBad()) {
334 }
else if (s.isGood()) {
340 int totes = good + severe + badish + unk;
341 return MessageFormat.format(
" {0}: {1} %: {2} OK, {3} bad, " 342 +
"{4} warnings and {5} unknown. " 343 +
"= {6} items.\n", statId, 100 * good / totes,
344 good, severe, badish, unk, totes);
355 Collection<ReportItem> stats =
new ArrayList<ReportItem>();
356 for (String statId : statistics.keySet()) {
359 stats.addAll(statistics.get(statId));
364 }
else if (s.isBad()) {
366 }
else if (s.isGood()) {
372 int totes = good + severe + badish + unk;
374 return MessageFormat.format(
" {0}: {1} %: {2} OK, {3} bad, " 375 +
"{4} warnings and {5} unknown. " 376 +
"= {6} items.\n",
"Total", 100 * good / totes,
377 good, severe, badish, unk, totes);
379 return "no elements present.";
388 for (Map.Entry<String, Collection<ReportItem>> kv
389 : statistics.entrySet()) {
402 Collection<ReportItem> stats = statistics.get(statId);
403 String rv = MessageFormat.format(
"{0}:\n", statId);
407 rv += s.getSummary() +
"\n";
412 if (suppressed != 0) {
413 rv += MessageFormat.format(
"{0} warnings and notes hidden\n",
424 Collection<ReportItem> stats = statistics.get(statId);
425 String rv = MessageFormat.format(
"{0}:\n", statId);
429 rv += s.getSummary() +
"\n";
434 if (suppressed != 0) {
435 rv += MessageFormat.format(
"{0} notes hidden\n",
445 String rv =
"Errors:\n";
446 for (Map.Entry<String, Collection<ReportItem>> kv
447 : statistics.entrySet()) {
457 String rv =
"Warnings:\n";
458 for (Map.Entry<String, Collection<ReportItem>> kv
459 : statistics.entrySet()) {
469 Collection<ReportItem> stats = statistics.get(statId);
470 String rv = MessageFormat.format(
"{0}:\n", statId);
473 rv += s.toString() +
"\n";
478 rv += s.toString() +
"\n";
488 String rv =
"All reports\n";
489 for (Map.Entry<String, Collection<ReportItem>> kv
490 : statistics.entrySet()) {
500 Collection<ReportItem> allStats =
new ArrayList<ReportItem>();
501 for (Map.Entry<String, Collection<ReportItem>> kv
502 : statistics.entrySet()) {
503 allStats.addAll(kv.getValue());
512 Collection<ReportItem> errorStats =
new ArrayList<ReportItem>();
513 Collection<ReportItem> onlyerrorStats =
new ArrayList<ReportItem>();
514 for (Map.Entry<String, Collection<ReportItem>> kv
515 : statistics.entrySet()) {
516 errorStats.addAll(kv.getValue());
522 onlyerrorStats.add(ri);
526 return onlyerrorStats;
534 for (Map.Entry<String, Collection<ReportItem>> kfj
535 : statistics.entrySet()) {
547 for (Map.Entry<String, Collection<ReportItem>> kfj
548 : statistics.entrySet()) {
559 Collection<ReportItem> stats = statistics.get(statId);
569 }
else if (s.isSevere()) {
571 }
else if (s.isBad()) {
573 }
else if (s.isGood()) {
581 String patternDate =
"yyyy-MM-dd";
582 SimpleDateFormat simpleDateFormat =
new SimpleDateFormat(patternDate);
583 String date = simpleDateFormat.format(
new Date());
584 String patternTime =
"hh:mm:ssZ";
585 SimpleDateFormat simpleTimeFormat =
new SimpleDateFormat(patternTime);
586 String time = simpleTimeFormat.format(
new Date());
587 String dateTime = date +
"T" + time;
589 String corpusname = corpus.getCorpusName();
598 String corpuswords = corpus.getCorpusWords();
599 String corpussents = corpus.getCorpusSentenceNumber();
600 String corpustrans = corpus.getCorpusTranscriptionNumber();
601 String corpusspeaks = corpus.getCorpusSpeakerNumber();
602 String corpuscomms = corpus.getCorpusCommunicationNumber();
604 line =
"{ \"index\": { \"_index\": \"inel-curation\", \"_type\": \"corpus-service-report\" }}\n{ \"doc\": { \"corpus\": \"" 605 + corpusname +
"\", \"name\": \"" + statId +
"\", \"method\": \"fix\", \"date\": \"" 606 + dateTime +
"\", \"ok\": " + good +
", \"bad\": " + severe +
", \"fixed\": " 607 + fix +
", \"corpus-words\": " + corpuswords +
", \"corpus-sentences\": " + corpussents +
", \"corpus-transcriptions\": " + corpustrans
608 +
", \"corpus-speaker\": " + corpusspeaks +
", \"corpus-communications\": " + corpuscomms +
" }}\n";
616 Collection<ReportItem> stats = statistics.get(statId);
626 }
else if (s.isSevere()) {
628 }
else if (s.isBad()) {
630 }
else if (s.isGood()) {
638 String patternDate =
"yyyy-MM-dd";
639 SimpleDateFormat simpleDateFormat =
new SimpleDateFormat(patternDate);
640 String date = simpleDateFormat.format(
new Date());
641 String patternTime =
"hh:mm:ssZ";
642 SimpleDateFormat simpleTimeFormat =
new SimpleDateFormat(patternTime);
643 String time = simpleTimeFormat.format(
new Date());
644 String dateTime = date +
"T" + time;
646 line =
"{ \"index\": { \"_index\": \"inel-curation\", \"_type\": \"corpus-service-report\" }}\n{\"doc\": { \"name\": \"" + statId +
"\", \"method\": \"fix\", \"date\": \"" + dateTime +
"\", \"ok\": " + good +
", \"bad\": " + severe +
", \"fixed\": " + fix +
" }}\n";
void addReportItem(String statId, ReportItem reportItem)
void addWarning(String statId, CorpusData cd, String description)
void addMissing(String statId, String description)
void addNote(String statId, String description)
void addNote(String statId, CorpusData cd, String description)
String getErrorReport(String statId)
void addCritical(String statId, String description)
String getWarningReport(String statId)
void addWarning(String statId, String description, String extraBlah)
void addCorrect(String statId, String filename, String description)
void addCritical(String statId, Throwable e, String description, String extrablah)
void addCritical(String statId, CorpusData cd, String description)
Collection< ReportItem > getRawStatistics()
void addWarning(String statId, Throwable e, String description, String extrablah)
void addNote(String statId, String description, String extraBlah)
void addCorrect(String statId, CorpusData cd, String description)
void addCritical(String description)
void addException(Throwable e, String statId, CorpusData cd, String description)
void addNote(String statId, Throwable e, String description)
void addWarning(String statId, String description)
void addMissing(String statId, CorpusData cd, String description)
void addCorrect(String statId, String description)
void addNote(String statId, Throwable e, String description, String extrablah)
String getSummaryLine(String statId)
String getFullReport(String statId)
String getAllAsSummaryLine()
String getFixJson(Corpus corpus)
String getFixLine(String statId)
void addException(Throwable e, String description)
void addCritical(String statId, Throwable e, String description)
void addException(String statId, Throwable e, String description)
Collection< ReportItem > getErrorStatistics()
String getWarningReports()
String getFixLine(String statId, Corpus corpus)
void addException(String statId, Throwable e, String description, String extrablah)
void addCritical(String statId, String description, String extraBlah)
void addFix(String statId, CorpusData cd, String description)