(Tuple input)
| 73 | } |
| 74 | |
| 75 | public DataBag exec(Tuple input) throws IOException { |
| 76 | if (input == null || input.size() == 0) |
| 77 | return null; |
| 78 | try{ |
| 79 | DataBag output = DefaultBagFactory.getInstance().newDefaultBag(); |
| 80 | DataBag in = (DataBag)input.get(0); |
| 81 | |
| 82 | Map<String, Long> pairs = new HashMap<String, Long>(); |
| 83 | List<Long> counts = new ArrayList<Long> (); |
| 84 | |
| 85 | Iterator<Tuple> it = in.iterator(); |
| 86 | while (it.hasNext()) { |
| 87 | Tuple t = it.next(); |
| 88 | String hour = (String)t.get(1); |
| 89 | Long count = (Long)t.get(2); |
| 90 | pairs.put(hour, count); |
| 91 | counts.add(count); |
| 92 | } |
| 93 | |
| 94 | double mean = computeMean(counts); |
| 95 | double standardDeviation = computeSD(counts, mean); |
| 96 | |
| 97 | Iterator<String> it2 = pairs.keySet().iterator(); |
| 98 | while (it2.hasNext()) { |
| 99 | String hour = it2.next(); |
| 100 | Long count = pairs.get(hour); |
| 101 | if ( count > mean ) { |
| 102 | Tuple t = TupleFactory.getInstance().newTuple(4); |
| 103 | t.set(0, hour); |
| 104 | t.set(1, ((double) count - mean) / standardDeviation ); // the score |
| 105 | t.set(2, count); |
| 106 | t.set(3, mean); |
| 107 | output.add(t); |
| 108 | } |
| 109 | } |
| 110 | return output; |
| 111 | }catch (Exception e){ |
| 112 | System.err.println("ScoreGenerator: failed to process input; error - " + e.getMessage()); |
| 113 | return null; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | /** |
nothing calls this directly
no test coverage detected