-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubtask11.java
80 lines (65 loc) · 2.48 KB
/
subtask11.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package test2;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.json.JSONArray;
import org.json.JSONObject;
public class subtask11
{
public static void main( String[] args ) throws Exception
{
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "Damage recieved per champion");
job.setJarByClass(subtask11.class);
job.setMapperClass(st5Mapper.class);
job.setCombinerClass(st5Reducer.class);
job.setReducerClass(st5Reducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setNumReduceTasks(20);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
static class st5Mapper extends Mapper<Object, Text, Text, IntWritable> {
private Text champion = new Text();
private Text write = new Text();
private IntWritable dam;
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
String jsonString = value.toString();
JSONObject obj = new JSONObject(jsonString);
JSONObject data = (JSONObject)obj.get("data");
JSONArray damageEvents = data.getJSONArray("damageEvents");
for (int j = 0; j < damageEvents.length(); j++)
{
JSONObject o = damageEvents.getJSONObject(j);
int championID = o.getInt("receiverUnitID");
int damage = o.getInt("damage");
int res = damage;
dam= new IntWritable(res);
String op = Integer.toString(championID);
champion.set(String.valueOf(op));
write.set(champion);
context.write(write, dam);
}
}
}
static class st5Reducer extends Reducer<Text, IntWritable, Text, IntWritable> {
private IntWritable numGames = new IntWritable();
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
Integer win = 0;
for (IntWritable val : values) {
win += val.get();
}
numGames.set(win);
context.write(key, numGames);
}
}
}