public override void Reduce(string key, IEnumerable<string> values, ReducerCombinerContext context)
        {
            int numberOfItems = 0;
            double totalPrice = 0.0d;

            foreach (string price in values)
            {
                decimal value;
                if (Decimal.TryParse(price, out value))
                {
                    // It's a decimal
                    numberOfItems++;
                    totalPrice += (double)value;
                }
                else
                {
                    // No it's not.
                    numberOfItems++;
                    totalPrice += (double)0;
                }
            }

            // Pass the average actual cost of all peppermint oil to output
            string combinedText = "Average Actual Cost of is " + Math.Round(totalPrice / numberOfItems, 2) + ", for " +
               numberOfItems + " Items";

            context.EmitKeyValue(key, combinedText);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ds112/hbase-on-windows
            public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
            {
                int    size       = 0;
                long   TotalUsage = 0;
                string temp       = string.Empty;
                var    arr        = values.ToArray();

                foreach (String value in arr)
                {
                    string[] column          = value.Split('\t');
                    int      temp_totalUsage = int.Parse(column[4].Trim(' '));

                    //Calculate total number of Byte used by Host / IP
                    TotalUsage += temp_totalUsage;

                    //Filter the HostName by maximum number of Byte used.
                    if (temp_totalUsage > size)
                    {
                        size = temp_totalUsage;
                        temp = value;
                    }

                    if (arr.Last() == value)
                    {
                        context.EmitKeyValue(column[0], "\t" + size + "\t" + TotalUsage);
                    }
                }
            }
        public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
        {
            double totalPrice = 0.0d;
            string postcode   = "";

            foreach (string item in values)
            {
                decimal value;
                if (Decimal.TryParse(item, out value))
                {
                    // It's a actual cost
                    totalPrice += (double)value;
                }
                else
                {
                    // No it's not it is a PostCode.
                    postcode = item;
                }
            }


            if (postcode != "")
            {
                // Pass the highest actual spend of each Post Code
                string outputText = "Total Actual Cost in PostCode - " + postcode.Trim() + " Total Cost - " + totalPrice.ToString("0.00");
                context.EmitKeyValue(postcode, outputText);
            }
        }
        public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
        {
            // Pass the total Practices count to output
            string outputText = "Total Number of Practises in UK - " + values.Count();

            context.EmitKeyValue(key, outputText);
        }
        public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
        {
            int    numberOfItems = 0;
            double totalPrice    = 0.0d;

            foreach (string price in values)
            {
                decimal value;
                if (Decimal.TryParse(price, out value))
                {
                    // It's a decimal
                    numberOfItems++;
                    totalPrice += (double)value;
                }
                else
                {
                    // No it's not.
                    numberOfItems++;
                    totalPrice += (double)0;
                }
            }

            // Pass the average actual cost of all peppermint oil to output
            string combinedText = "Average Actual Cost of is " + Math.Round(totalPrice / numberOfItems, 2) + ", for " +
                                  numberOfItems + " Items";

            context.EmitKeyValue(key, combinedText);
        }
コード例 #6
0
        public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
        {
            var vehileKilometerSensorData = values.Select(v => double.Parse(v)).ToList();
            var totalKilometers           = vehileKilometerSensorData.Max() - vehileKilometerSensorData.Min();

            context.EmitKeyValue(key, totalKilometers.ToString(CultureInfo.InvariantCulture));
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: mreeddev/Hadoop-Analysis
        public override void Reduce(string key, IEnumerable <string> lines, ReducerCombinerContext context)
        {
            double TREND_IMPORTANCE = 0;
            var    countriesScores  = new List <CountryScore>();
            var    indicatorConf    = new IndicatorSettings();
            double sum = 0;

            foreach (var line in lines)
            {
                var data       = new CountryScore();
                var dataString = line.Split('\t');
                data.CountryName   = dataString[1];
                data.CountryCode   = dataString[0];
                data.Trend         = Double.Parse(dataString[2]);
                data.OriginalValue = Double.Parse(dataString[3]);

                sum += data.OriginalValue;
                countriesScores.Add(data);
            }
            //smothen the values distribution along the mean by 1/3

            var avg = sum / countriesScores.Count();

            foreach (var val in countriesScores)
            {
                val.Value = val.OriginalValue + (avg - val.OriginalValue) / 2;
                val.Value = indicatorConf.AdjustValue(key, val.Value, val.Trend * TREND_IMPORTANCE);
                // context.EmitKeyValue(val.CountryCode, key + '\t' + val.Value + "\t val=" + val.OriginalValue);
                context.EmitKeyValue(val.CountryCode, val.CountryName + '\t' + val.Value + "\t" + val.OriginalValue + "\t" + key);
            }
        }
        public override void Reduce(string key, IEnumerable<string> values, ReducerCombinerContext context)
        {
            double totalPrice = 0.0d;
            string postcode = "";

            foreach (string item in values)
            {
                decimal value;
                if (Decimal.TryParse(item, out value))
                {
                    // It's a actual cost
                    totalPrice += (double)value;
                }
                else
                {
                    // No it's not it is a PostCode.
                    postcode = item;
                }
            }

            
            if (postcode != "")
            {
                // Pass the highest actual spend of each Post Code
                string outputText = "Total Actual Cost in PostCode - " + postcode.Trim() + " Total Cost - " + totalPrice.ToString("0.00");
                context.EmitKeyValue(postcode, outputText);
            }

        }
        public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
        {
            var average = values.Select(s => s.Split(','))
                          .Select(x => (DateTime.Parse(x[1]) - DateTime.Parse(x[0])).TotalMinutes)
                          .Average();

            context.EmitKeyValue(key, average.ToString());
        }
コード例 #10
0
            public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
            {
                context.IncrementCounter(context.IsCombiner ? "combineInputs" : "reduceInputs");
                string sum = values.Sum(s => long.Parse(s)).ToString();

                context.Log(string.Format("Combine/Reduce::  {0},{1}", key, sum));
                context.EmitKeyValue(key, sum);
            }
コード例 #11
0
ファイル: Program.cs プロジェクト: Alfredovec/HadoopSandbox
            public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
            {
                var totalCount = 0;

                values.ToList().ForEach(v => totalCount += int.Parse(v));

                context.EmitKeyValue(key, "- Total count: " + totalCount);
            }
コード例 #12
0
 public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
 {
     // for each record display column 2 and 4
     foreach (string val in values)
     {
         context.EmitKeyValue(key, val.Split('\t')[3]);
     }
 }
コード例 #13
0
        public override void Reduce(string key, IEnumerable<string> values, ReducerCombinerContext context)
        {
            // Key is the vehicle ID, values are double values for driven kilometers
            // We need to add up the kilometers.
            var totalDriven = values.Select(v => double.Parse(v)).Sum();

            context.EmitKeyValue(key, totalDriven.ToString(CultureInfo.InvariantCulture));
        }
コード例 #14
0
        public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
        {
            // Key is the vehicle ID, values are double values for driven kilometers
            // We need to add up the kilometers.
            var totalDriven = values.Select(v => double.Parse(v)).Sum();

            context.EmitKeyValue(key, totalDriven.ToString(CultureInfo.InvariantCulture));
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: ds112/hbase-on-windows
 public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
 {
     // Finding the special charaters and non-alphabatic characters from input and replace it with empty string value.
     foreach (string val in values)
     {
         string st = Regex.Replace(val, @"[^0-9a-zA-Z]+", "");
         context.EmitKeyValue(key, st.ToString());
     }
 }
コード例 #16
0
        public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
        {
            var seek = values.GroupBy(x => x).OrderByDescending(x => x.Count()).First();

            string tmp =
                string.Concat(seek.Key, "\t\t", "Count:", "\t", seek.Key.Count().ToString());

            context.EmitKeyValue(key, tmp);
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: ds112/hbase-on-windows
 public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
 {
     //Sum up the values which has common key
     foreach (String value in values)
     {
         Count++;
     }
     //Emits the number of values available for each key in ascending order
     context.EmitKeyValue(key, Count.ToString());
 }
コード例 #18
0
        public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
        {
            //Get the sum of values per key.  This will return our final counts.
            long numberOfCrimes = values.Sum(e => long.Parse(e));

            if (numberOfCrimes >= 400)
            {
                context.EmitKeyValue(key, numberOfCrimes.ToString());
            }
        }
コード例 #19
0
        public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
        {
            string all = "";

            foreach (string a in values)
            {
                all += a;
            }

            context.EmitLine(all);
        }
コード例 #20
0
ファイル: Program.cs プロジェクト: ds112/hbase-on-windows
            public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
            {
                int _count = 0;

                // For each key calculate count of values
                foreach (string val in values)
                {
                    _count++;
                }
                context.EmitKeyValue(key, _count.ToString());
            }
コード例 #21
0
ファイル: Program.cs プロジェクト: ds112/hbase-on-windows
            public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
            {
                int count = 0;

                foreach (string val in values)
                {
                    //Count number of visitors based on hours
                    count++;
                }
                context.EmitKeyValue(key + "-" + (Convert.ToInt16(key) + 1).ToString() + " Hours :", count.ToString());
            }
コード例 #22
0
        public override void Reduce(string key, IEnumerable<string> values, ReducerCombinerContext context)
        {
            int totalSurveyTakers = 0;
            int totalFeedback = 0;

            foreach (string value in values)
            {
                totalSurveyTakers++;
                totalFeedback += int.Parse(value);
            }
            double avg = ((double)totalFeedback / (double)totalSurveyTakers);
            context.EmitKeyValue(key, avg.ToString());
        }
コード例 #23
0
ファイル: Reducer.cs プロジェクト: divyanshmalik/sa2014
        public override void Reduce(
            string key, 
            IEnumerable<string> values, 
            ReducerCombinerContext context)
        {
            string value = values
                .First()
                .Split(',')
                .Sum(x => Convert.ToDouble(x))
                .ToString();

            context.EmitKeyValue(key, value);
        }
        public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
        {
            double total = 0;
            double count = 0;

            foreach (var item in values)
            {
                count++;
                total += double.Parse(item);
            }

            context.EmitKeyValue(key, Math.Round(total / count, 2).ToString());
        }
コード例 #25
0
        public override void Reduce(
            string key,
            IEnumerable <string> values,
            ReducerCombinerContext context)
        {
            string value = values
                           .First()
                           .Split(',')
                           .Sum(x => Convert.ToDouble(x))
                           .ToString();

            context.EmitKeyValue(key, value);
        }
コード例 #26
0
ファイル: Program.cs プロジェクト: ds112/hbase-on-windows
            public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
            {
                //Split the contents based on the custom separator
                string[] keyvalue   = key.Split(new string[] { "~seperator~" }, StringSplitOptions.None);
                string   replacetxt = keyvalue[1].Replace('/', '-');

                foreach (string value in values)
                {
                    myCount++;
                }

                //Emits the resultant values
                context.EmitKeyValue(keyvalue[0].Trim(), "," + replacetxt + "," + myCount);
            }
コード例 #27
0
        public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
        {
            var allValuesForCountryKey        = values as List <string> ?? values.ToList();
            var numOfPurchases                = allValuesForCountryKey.Count();
            var numOfPurchasesFromNewVisitors = allValuesForCountryKey.Count(v => v == "New");

            context.EmitKeyValue(key,
                                 StringUtility.GetAsTabbedString(
                                     new[]
            {
                numOfPurchases.ToString(CultureInfo.InvariantCulture),
                Math.Round(100.0 * numOfPurchasesFromNewVisitors / numOfPurchases, 2).ToString(CultureInfo.InvariantCulture)
            }));
        }
コード例 #28
0
        public override void Reduce(string key, IEnumerable<string> values, ReducerCombinerContext context)
        {
            var allValuesForCountryKey = values as List<string> ?? values.ToList();
            var numOfPurchases = allValuesForCountryKey.Count();
            var numOfPurchasesFromNewVisitors = allValuesForCountryKey.Count(v => v == "New");

            context.EmitKeyValue(key,
                                 StringUtility.GetAsTabbedString(
                                                new[]
                                                {
                                                    numOfPurchases.ToString(CultureInfo.InvariantCulture),
                                                    Math.Round(100.0 * numOfPurchasesFromNewVisitors/numOfPurchases, 2).ToString(CultureInfo.InvariantCulture)
                                                }));
        }
コード例 #29
0
            public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
            {
                //Keyword to search for
                String keyword = "lya.colorado.edu";

                if (key == keyword)
                {
                    foreach (String value in values)
                    {
                        //returns the row which contains the keyword
                        context.EmitKeyValue("", value);
                    }
                }
            }
コード例 #30
0
ファイル: MySimpleReducer.cs プロジェクト: prilutskiy/SPOLKS
 public override void Reduce(string key, IEnumerable<string> values, ReducerCombinerContext context)
 {
     //initialize counters
     int myCount = 0;
     int mySum = 0;
     //count and sum incoming values
     foreach (string value in values)
     {
         mySum += int.Parse(value);
         myCount++;
     }
     //output results
     context.EmitKeyValue(key, myCount + "t" + mySum);
 }
コード例 #31
0
ファイル: Program.cs プロジェクト: ds112/hbase-on-windows
            public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
            {
                var   arr   = values.ToArray();
                Match match = null;

                //Performing filter operation using Regex. Match the key with error code '200'
                match = Regex.Match(key, ".*200.*", RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    foreach (String value in arr)
                    {
                        context.EmitKeyValue("", value);
                    }
                }
            }
コード例 #32
0
        public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
        {
            //initialize counters
            int myCount = 0;
            int mySum   = 0;

            //count and sum incoming values
            foreach (string value in values)
            {
                mySum += int.Parse(value);
                myCount++;
            }

            //output results
            context.EmitKeyValue(key, myCount + "\t" + mySum);
        }
コード例 #33
0
        public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
        {
            //context.Log(string.Format("Reducer: Key- {0}", key));
            var valuesForCountryKey    = values as List <string> ?? values.ToList();
            var totalEvidences         = valuesForCountryKey.Count();
            var totalPositiveResponses = valuesForCountryKey.Count(val => val == "Positive" || val == "Very Positive");
            var totalNeutralResponses  = valuesForCountryKey.Count(val => val == "Neutral");
            var totalNegativeResponses = valuesForCountryKey.Count(val => val == "Negative" || val == "Very Negative");

            //context.Log(string.Format("Emitting- {0} | {1}", key, (totalPositiveResponses / totalEvidences).ToString("P", CultureInfo.InvariantCulture)));
            context.EmitKeyValue(key, MRStringUtil.convertToTabbedString(
                                     new[] {
                (totalPositiveResponses / totalEvidences).ToString("P", CultureInfo.InvariantCulture),
                (totalNeutralResponses / totalEvidences).ToString("P", CultureInfo.InvariantCulture),
                (totalNegativeResponses / totalEvidences).ToString("P", CultureInfo.InvariantCulture),
            }));
        }
コード例 #34
0
        public override void Reduce(string key, IEnumerable<string> values, ReducerCombinerContext context)
        {
            try
            {
                var doubleValues = values.Select(double.Parse).ToList();

                var max = doubleValues.Max();
                var min = doubleValues.Min();
                var avg = doubleValues.Average();

                context.EmitKeyValue(string.Format("{0}_max", key), max.ToString(CultureInfo.InvariantCulture));
                context.EmitKeyValue(string.Format("{0}_min", key), min.ToString(CultureInfo.InvariantCulture));
                context.EmitKeyValue(string.Format("{0}_avg", key), avg.ToString(CultureInfo.InvariantCulture));
            }
            catch (Exception x)
            {
                context.EmitLine(x.ToString());
            }
        }
コード例 #35
0
ファイル: Program.cs プロジェクト: mreeddev/Hadoop-Analysis
        public override void Reduce(string key, IEnumerable <string> lines, ReducerCombinerContext context)
        {
            string[] lineData = null;
            //try
            //{
            Double sum        = 0;
            string country    = "n/a";
            var    indDetails = "";

            foreach (var line in lines)
            {
                lineData    = line.Split('\t');
                sum        += Double.Parse(lineData[1]);
                country     = lineData[0];
                indDetails += " " + lineData[3] + "=" + lineData[1];
            }
            context.EmitKeyValue(country + "(" + key + ")", sum.ToString() + indDetails);
            //}
            //catch (Exception ex)
            //{
            //    context.EmitLine(ex.Message);
            //}
        }
コード例 #36
0
 //Accepts each key and count the occurrances
 public override void Reduce(string key, IEnumerable <string> values,
                             ReducerCombinerContext context)
 {
     //Write back
     context.EmitKeyValue(key, values.Count().ToString());
 }
コード例 #37
0
 public override void Reduce(string key, IEnumerable<string> values, ReducerCombinerContext context)
 {
     //Get the sum of values per key.  This will return our final counts.
     context.EmitKeyValue(key, values.Sum(e => long.Parse(e)).ToString());
 }
コード例 #38
0
        public override void Reduce(string key, IEnumerable<string> values, ReducerCombinerContext context)
        {
            //count sightings by type
            try
            {
                //var query = from v in values
                //            group v by v into g
                //            select new
                //            {
                //                preptime = g.Count(),
                //            };

                //send results to output
                foreach (var item in values)
                {
                    context.EmitKeyValue(
                        key, item
                        );
                }
            }
            catch (InvalidCastException e)
            {
                context.EmitKeyValue(
                       "error", "error"
                       );
            }
        }
コード例 #39
0
 public override void Reduce(string key, IEnumerable<string> values, ReducerCombinerContext context)
 {
     var vehileKilometerSensorData = values.Select(v => double.Parse(v)).ToList();
     var totalKilometers = vehileKilometerSensorData.Max() - vehileKilometerSensorData.Min();
     context.EmitKeyValue(key, totalKilometers.ToString(CultureInfo.InvariantCulture));
 }
 public override void Reduce(string key, IEnumerable<string> values, ReducerCombinerContext context)
 {
     // Pass the total Practices count to output
     string outputText = "Total Number of Practises in UK - " + values.Count();
     context.EmitKeyValue(key, outputText);
 }
 public override void Reduce(string key, IEnumerable <string> values, ReducerCombinerContext context)
 {
     context.EmitKeyValue(key, values.Sum(v => int.Parse(v)).ToString(CultureInfo.InvariantCulture));
 }
コード例 #42
0
 public override void Reduce(string key, IEnumerable<string> values, ReducerCombinerContext context)
 {
     throw new NotImplementedException();
 }
コード例 #43
0
ファイル: Program.cs プロジェクト: mreeddev/Hadoop-Analysis
        public override void Reduce(string key, IEnumerable <string> lines, ReducerCombinerContext context)
        {
            var keyD = Double.Parse(key);

            context.EmitKeyValue((-keyD).ToString(), lines.FirstOrDefault());
        }
 public override void Reduce(string key, IEnumerable<string> values, ReducerCombinerContext context)
 {
     context.EmitKeyValue(key, values.Sum(v => int.Parse(v)).ToString(CultureInfo.InvariantCulture));
 }
コード例 #45
0
ファイル: Program.cs プロジェクト: abhaymise/Hadoop-Analysis
        public override void Reduce(string key, IEnumerable<string> lines, ReducerCombinerContext context)
        {
            double TREND_IMPORTANCE = 0;
            var countriesScores = new List<CountryScore>();
            var indicatorConf = new IndicatorSettings();
            double sum = 0;
            
            foreach (var line in lines)
            {
                var data = new CountryScore();
                var dataString = line.Split('\t');
                data.CountryName = dataString[1];
                data.CountryCode = dataString[0];
                data.Trend = Double.Parse(dataString[2]);
                data.OriginalValue = Double.Parse(dataString[3]);

                sum += data.OriginalValue;
                countriesScores.Add(data);
            }
            //smothen the values distribution along the mean by 1/3
            
                var avg = sum / countriesScores.Count();
           
             foreach (var val in countriesScores)
             {
                 val.Value = val.OriginalValue + (avg - val.OriginalValue) / 2;
                 val.Value = indicatorConf.AdjustValue(key, val.Value, val.Trend*TREND_IMPORTANCE);
                // context.EmitKeyValue(val.CountryCode, key + '\t' + val.Value + "\t val=" + val.OriginalValue);
                 context.EmitKeyValue(val.CountryCode,  val.CountryName + '\t' + val.Value + "\t" + val.OriginalValue+"\t"+key);
                
             }



        }
コード例 #46
0
ファイル: Program.cs プロジェクト: abhaymise/Hadoop-Analysis
        public override void Reduce(string key, IEnumerable<string> lines, ReducerCombinerContext context)
        {
            string[] lineData = null;
            //try
            //{
                Double sum = 0;
                string country = "n/a";
                var indDetails = "";
                foreach (var line in lines)
                {

                    lineData = line.Split('\t');
                    sum += Double.Parse(lineData[1]);
                    country = lineData[0];
                    indDetails += " " + lineData[3] + "=" + lineData[1];
                }
                context.EmitKeyValue(country + "(" + key + ")", sum.ToString() + indDetails);
            //}
            //catch (Exception ex)
            //{
            //    context.EmitLine(ex.Message);
            //}
        }
コード例 #47
0
ファイル: Program.cs プロジェクト: abhaymise/Hadoop-Analysis
 public override void Reduce(string key, IEnumerable<string> lines, ReducerCombinerContext context)
 {
     var keyD = Double.Parse(key);
     context.EmitKeyValue((-keyD).ToString(), lines.FirstOrDefault());
 }
コード例 #48
0
 public override void Reduce(string key, IEnumerable<string> values, ReducerCombinerContext context)
 {
     context.EmitKeyValue(key, values.Count().ToString());
 }