Data from each of the four sensors
Inheritance: SensorReadings
コード例 #1
0
        public static QuestionMessage CreateCurrentReadingQuestion(double[] overall_stats, SensorReadingsData data, double[] significances, SensorDefinition[] sensorDefinitions)
        {
            double[] value = new double[4] { data.Reading1, data.Reading2, data.Reading3, data.Reading4 };

             if (value.Length != significances.Length)
             {
            throw new ArgumentException("Must provide an equal amount of reading values and significance values");
             }
             if (value.Length != sensorDefinitions.Length)
             {
            throw new ArgumentException("Must provide an equal amount of reading values and sensor descriptions");
             }
             if (overall_stats.Length < 11)
             {
            throw new ArgumentException("Overall stats needs to be for at least 12 elements", "overall_stats");
             }
             double[] overall_means = new double[] { overall_stats[2], overall_stats[5], overall_stats[8], overall_stats[11] };

             // Find out how many of the readings are significant
             List<int> significant_reading_indexes = new List<int>();
             for (int i = 0; i < value.Length; i++)
             {
            if (significances[i] > significance_threshold)
            {
               significant_reading_indexes.Add(i);
            }
             }
             // If some readings are significant, randomly choose one to ask about
             if (significant_reading_indexes.Count > 0)
             {
            Random rand = new Random();
            int chosen_index = Convert.ToInt32(Math.Floor(rand.Next(significant_reading_indexes.Count)));
            int chosen_reading_index = significant_reading_indexes[chosen_index];
            double chosen_value = value[chosen_reading_index];
            // A reading and sensor have been selected, socreate the question
            QuestionMessage qMessage = new QuestionMessage();
            string message_string;
            // Now one is chosen, work out whether it's high or low

            // Message substitution index
            // 0: Reading time
            // 1: Sensor Name
            // 2: Reading value
            // 3: Unit

            if (overall_means[chosen_reading_index] < chosen_value)
            {
               message_string = "We think the {1} is high at the moment... what do you think?  What might have caused this?";
            }
            else
            {
               message_string = "Low {1} readings have been detected, has anything happend that might explain this?";
            }
            qMessage.Text = String.Format(message_string,
                data.Time.ToLocalTime().ToShortTimeString(),
                sensorDefinitions[chosen_reading_index].Name.ToLower(),
                value[chosen_reading_index],
                sensorDefinitions[chosen_reading_index].Unit);
            return qMessage;
             }
             else
             {
            return null;
             }
        }
コード例 #2
0
 public static void SerializeSensorReadingsData(MemoryStream ms, SensorReadingsData data)
 {
     SensorReadingsDataSerializer.Serialize(ms, data);
 }