Пример #1
0
        private void filterAndSave(string line)
        {
            //split timestamp and value
            string[] substrings = line.Split(' ');
            if (substrings.Length > 1)
            {
                if (this.starttime != new DateTime(2000, 1, 1) && this.endtime != new DateTime(2000, 1, 1)) //check if time filter is set
                {
                    filterByTime(this.starttime, this.endtime);                                             //check if timestamp fits between start and endtime
                }
                else
                {
                    fitsTimeFilter = true;
                }

                if (this.types != null && fitsTimeFilter) //check if any type filters are set and if time is right
                {
                    filterByType();
                }
                else
                {
                    fitsTypeFilter = true;
                }

                if (this.application != null && fitsTimeFilter && fitsTypeFilter) //check if any application filters are set and if time and types are right
                {
                    filterByApplication();
                }
                else
                {
                    fitsApplicationFilter = true;
                }

                if (fitsTimeFilter && fitsTypeFilter && fitsApplicationFilter) //check if data fits all filters
                {
                    temp = new MeterData(REDDMeter.GetMeterId());
                    temp.SetTimestamp(substrings[0]);
                    temp.SetPowerP1(Convert.ToDouble(substrings[1], CultureInfo.InvariantCulture));
                    myDatabase.InsertMeterDataIntoDb(temp);
                }
                fitsTimeFilter        = false;
                fitsTypeFilter        = false;
                fitsApplicationFilter = false;
            }
        }
Пример #2
0
        private void workDisagregationFile(String path)
        {
            String[] paths = path.Split('\\');

            ///For later usage to find the household
            String household       = paths[paths.Count() - 2];
            int    householdNumber = (int)Char.GetNumericValue(household[household.Count() - 1]);

            ///Device identifier
            String device = paths[paths.Count() - 1];

            String[] deviceParts        = device.Split('.');
            String[] furtherDeviceParts = deviceParts[0].Split('_');
            int      deviceNumber       = Int32.Parse(furtherDeviceParts[1]);

            bool filterOk = false;

            ///Filter for appliance
            if (this.application != null)
            {
                foreach (ApplicationEnum currentApp in this.application)
                {
                    filterOk |= this.compareApplicationEnumWithCurrentHouseholdApp(currentApp, householdNumber, deviceNumber);
                }
            }
            else
            {
                filterOk = true;
            }

            if (filterOk == true)
            {
                using (StreamReader file = new StreamReader(path))
                {
                    if (file != null)
                    {
                        String line = "";
                        while ((line = file.ReadLine()) != null)
                        {
                            if (line != null)
                            {
                                String[] values = line.Split(' ');

                                String[] PowerValues = new String[(values.Count())];


                                if (!swapTimestampifSecondsPassed(values[0]))
                                {
                                    continue;
                                }

                                ///Only store data to database if the current timestamp is in the given boundries
                                if (Int32.Parse(values[0]) < this.getUnixTimestampFromDate(this.starttime) || Int32.Parse(values[0]) > this.getUnixTimestampFromDate(this.endtime) && this.filterByTimeEnabled)
                                {
                                }
                                else
                                {
                                    for (int i = 0; i < values.Count(); i++)
                                    {
                                        PowerValues[i] = values[i];
                                    }

                                    ///CHANGE TO REAL METERS
                                    MeterData temp = new MeterData(this.housesList[0].Item1);
                                    temp.SetTimestamp(values[0]);
                                    temp.SetPowerP1(Convert.ToDouble(values[1]));

                                    myDatabase.InsertMeterDataIntoDb(temp);
                                }
                            }
                        }
                    }
                }
                Console.WriteLine("Loaded " + household + " " + device + " sucessfully!");
            }
        }
Пример #3
0
        protected override void processFile(String path)
        {
            //open file
            //get datastream
            //save data --> not implemented yet
            //close file
            StreamReader reader = new StreamReader(File.OpenRead(path));

            if (reader != null)
            {
                String line;
                while ((line = reader.ReadLine()) != null)
                {
                    Console.WriteLine(line);
                    Console.WriteLine();

                    String[] values = line.Split(',');

                    if (sort == false)
                    {
                        if (isU)
                        {
                            String[] voltage = new String[values.Count()];

                            for (int i = 0; i < values.Count(); i++)
                            {
                                voltage[i] = values[i];
                            }

                            int countFrequency = 0;
                            foreach (String value in voltage)
                            {
                                if ((countFrequency % frequenzy) == 0)
                                {
                                    MeterData temp = new MeterData(ADRESMeterId);
                                    temp.SetVoltage(Convert.ToDouble(value, CultureInfo.InvariantCulture));

                                    myDatabase.InsertMeterDataIntoDb(temp);
                                }
                                countFrequency++;
                            }
                        }
                        else
                        {
                            String[] power = new String[values.Count()];

                            for (int i = 0; i < values.Count(); i++)
                            {
                                power[i] = values[i];
                            }

                            int counter = 0;
                            foreach (String value in power)
                            {
                                if (this.frequenzy == 0)
                                {
                                    this.frequenzy = 1;
                                }

                                if ((counter % (2 * frequenzy) == 0))
                                {
                                    MeterData temp = new MeterData(ADRESMeterId);
                                    temp.SetPowerP1(Convert.ToDouble(value, CultureInfo.InvariantCulture));
                                    myDatabase.InsertMeterDataIntoDb(temp);
                                }

                                counter++;
                            }
                        }
                    }
                    else
                    {
                        if (sortU)
                        {
                            if (isU)
                            {
                                String[] voltage = new String[values.Count()];

                                for (int i = 0; i < values.Count(); i++)
                                {
                                    voltage[i] = values[i];
                                }

                                int countFrequency = 0;
                                foreach (String value in voltage)
                                {
                                    if (this.frequenzy == 0)
                                    {
                                        this.frequenzy = 1;
                                    }

                                    if ((countFrequency % frequenzy) == 0)
                                    {
                                        MeterData temp = new MeterData(ADRESMeterId);
                                        temp.SetVoltage(Convert.ToDouble(value, CultureInfo.InvariantCulture));
                                        myDatabase.InsertMeterDataIntoDb(temp);
                                    }
                                    countFrequency++;
                                }
                            }
                        }
                        if (sortP)
                        {
                            String[] power = new String[values.Count()];

                            for (int i = 0; i < values.Count(); i++)
                            {
                                power[i] = values[i];
                            }

                            int counter = 0;
                            foreach (String value in power)
                            {
                                if (this.frequenzy == 0)
                                {
                                    this.frequenzy = 1;
                                }

                                if ((counter % (2 * frequenzy)) == 0)
                                {
                                    MeterData temp = new MeterData(ADRESMeterId);
                                    temp.SetPowerP1(Convert.ToDouble(value, CultureInfo.InvariantCulture));
                                    myDatabase.InsertMeterDataIntoDb(temp);
                                }

                                counter++;
                            }
                        }
                    }
                }
                reader.Close();
            }
        }
        private void workFile(string path)
        {
            String[] pathParts = path.Split('\\');
            String   household = pathParts[pathParts.Count() - 2];

            StreamReader file = new StreamReader(path);

            if (file != null)
            {
                //First line gets lost here on purpose
                String line = file.ReadLine();

                while ((line = file.ReadLine()) != null)
                {
                    if (line != null)
                    {
                        String[] values = line.Split(',');

                        ///The file reader can overflow. This protects that case
                        if (values[0] == "timestamp")
                        {
                            break;
                        }

                        String[] PowerValues = new String[(values.Count() - 1)];

                        for (int i = 1; i < values.Count(); i++)
                        {
                            PowerValues[i - 1] = values[i];
                        }

                        ///Aplication filter
                        List <int> foundIndicesWithDuplicates    = new List <int>();
                        List <int> foundIndicesWithoutDuplicates = new List <int>();
                        if (this.application != null)
                        {
                            foreach (ApplicationEnum currentCheckApplication in this.application)
                            {
                                int startAplicationList = this.currentHouseholdNumber * 9;
                                for (int i = startAplicationList; i < startAplicationList + 9; i++)
                                {
                                    if (currentCheckApplication == this.meterList[i].Item2)
                                    {
                                        foundIndicesWithDuplicates.Add(i - (9 * startAplicationList));
                                    }
                                }
                            }
                            foundIndicesWithoutDuplicates = foundIndicesWithDuplicates.Distinct().ToList();
                        }
                        int j = 0;
                        foreach (String value in PowerValues)
                        {
                            if (j == 0)
                            {
                                ///If value timestamp is out of timestampvalue / Filter by time
                                if ((Int32.Parse(removeMilisFromTimestamp(values[0])) < this.getUnixTimestampFromDate(this.starttime) || Int32.Parse(removeMilisFromTimestamp(values[0])) > this.getUnixTimestampFromDate(this.endtime)) && this.filterByTimeEnabled)
                                {
                                    break;
                                }

                                ///Checks if the given accuracy time has already passed. if not, break out.
                                if (!swapTimestampifSecondsPassed(values[0]))
                                {
                                    break;
                                }
                            }

                            if (foundIndicesWithoutDuplicates.Count != 0)
                            {
                                foreach (int searchedIndex in foundIndicesWithoutDuplicates)
                                {
                                    if (j == searchedIndex)
                                    {
                                        MeterData temp = new MeterData(getMeterId(j));
                                        temp.SetTimestamp(removeMilisFromTimestamp(values[0]));

                                        if (value == "NULL")
                                        {
                                            temp.SetPowerP1(Convert.ToDouble(0.0, CultureInfo.InvariantCulture));
                                        }
                                        else
                                        {
                                            temp.SetPowerP1(Convert.ToDouble(value, CultureInfo.InvariantCulture));
                                        }

                                        myDatabase.InsertMeterDataIntoDb(temp);
                                    }
                                }
                            }
                            else
                            {
                                MeterData temp = new MeterData(getMeterId(j));
                                temp.SetTimestamp(removeMilisFromTimestamp(values[0]));

                                if (value == "NULL")
                                {
                                    temp.SetPowerP1(Convert.ToDouble(0.0, CultureInfo.InvariantCulture));
                                }
                                else
                                {
                                    temp.SetPowerP1(Convert.ToDouble(value, CultureInfo.InvariantCulture));
                                }

                                myDatabase.InsertMeterDataIntoDb(temp);
                            }
                            j++;
                        }
                    }
                }
            }
        }