Example #1
0
        public override void ParseDirectory()
        {
            //low_freq
            string low_freq = this.Path + "\\00_original Data\\low_freq";

            string[] houseEntries = Directory.GetFileSystemEntries(low_freq);
            foreach (string house in houseEntries)
            {
                Console.WriteLine("House: " + house[house.Length - 1]);

                string[] fileEntries = Directory.GetFileSystemEntries(house);

                //read the labels file
                StreamReader reader    = new StreamReader(house + "\\labels.dat");
                string       labelFile = reader.ReadToEnd().Replace("\r\n", "\n").Replace("\n\r", "\n");
                //create a seperate string for each label
                string[] labels = labelFile.Split(new char[] { '\n' });

                for (int i = 0; i < labels.Length; i++)
                {
                    //split label name and number (tmp[0] = number, tmp[1] = name)
                    string[] tmp = labels[i].Split();
                    for (int j = 0; j < fileEntries.Length; j++)
                    {
                        //search through the files untill the file that belongs to the label is found
                        if ((fileEntries[j].Replace((house + "\\"), "")).Equals("channel_" + tmp[0] + ".dat"))
                        {
                            REDDMeter = new MeterManagementData();
                            REDDMeter.SetDescribtion("REDD-0" + house[house.Length - 1]);
                            processFile_LowFreq(tmp[1], fileEntries[j]);
                        }
                    }
                }
            }
        }
Example #2
0
        public void InsertMeterManagementData(MeterManagementData newData)
        {
            this.ConnectToDB();
            try
            {
                String sqlCommand = @"INSERT INTO meter_management VALUES (@p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11)";

                using (SqlCommand cmd = new SqlCommand(sqlCommand, connection))
                {
                    String[] data = newData.GetData();

                    cmd.Parameters.AddWithValue("@p1", Int32.Parse(data[0]));
                    cmd.Parameters.AddWithValue("@p2", Int32.Parse(data[1]));
                    cmd.Parameters.AddWithValue("@p3", Int32.Parse(data[2]));
                    cmd.Parameters.AddWithValue("@p4", Int32.Parse(data[3]));
                    cmd.Parameters.AddWithValue("@p5", Int32.Parse(data[4]));
                    cmd.Parameters.AddWithValue("@p6", data[5]);
                    cmd.Parameters.AddWithValue("@p7", data[6]);
                    cmd.Parameters.AddWithValue("@p8", data[7]);
                    cmd.Parameters.AddWithValue("@p9", Int32.Parse(data[8]));
                    cmd.Parameters.AddWithValue("@p10", data[9]);
                    cmd.Parameters.AddWithValue("@p11", data[10]);

                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                this.CloseConnection();
            }
            this.CloseConnection();
        }
        protected override void fillDBWithMeters()
        {
            CustomerData tempCustomer = new CustomerData();
            int          customerId   = tempCustomer.FillEmptyCustomer();

            myDatabase.InsertCustomerData(tempCustomer);

            MeterManufactorData tempMeterManufactor = new MeterManufactorData();
            int meterManufactorId = tempMeterManufactor.FillEmptyMeterManufactor();

            myDatabase.InsertMeterManufactorData(tempMeterManufactor);

            MeterProtocolData tempMeterProtocol = new MeterProtocolData();
            int meterProtocolId = tempMeterProtocol.FillEmptyMeterProtocol();

            myDatabase.InsertMeterProtocolData(tempMeterProtocol);

            MeterTypeData tempMeterType = new MeterTypeData();
            int           meterTypeId   = tempMeterType.FillEmptyMeterType();

            myDatabase.InsertMeterTypeData(tempMeterType);

            for (int i = 0; i < 81; i++)
            {
                int HomeNbr        = i / 9;
                int ApplicationNbr = i % 9;

                MeterManagementData GREENDMeter = new MeterManagementData();
                GREENDMeter.SetCustomerId(customerId);
                GREENDMeter.SetManufactorId(meterManufactorId);
                GREENDMeter.SetProtolId(meterProtocolId);
                GREENDMeter.SetTypeId(meterTypeId);
                GREENDMeter.SetDescribtion("GREEND-" + HomeNbr + "-" + ApplicationNbr);
                GREENDMeter.SetKey("not availiable");
                GREENDMeter.SetPeriod(1);
                GREENDMeter.SetPort("not availiable");
                GREENDMeter.SetSerial("not availiable");
                GREENDMeter.SetActive(true);
                myDatabase.InsertMeterManagementData(GREENDMeter);

                Tuple <int, ApplicationEnum> temp = new Tuple <int, ApplicationEnum>(GREENDMeter.GetMeterId(), this.getEnumFromGREENDEnumId((HomeNbr * 9) + ApplicationNbr));
                this.meterList.Add(temp);
            }
        }
Example #4
0
        protected override void fillDBWithMeters()
        {
            CustomerData tempCustomer = new CustomerData();
            int          customerId   = tempCustomer.FillEmptyCustomer();

            myDatabase.InsertCustomerData(tempCustomer);

            MeterManufactorData tempMeterManufactor = new MeterManufactorData();
            int meterManufactorId = tempMeterManufactor.FillEmptyMeterManufactor();

            myDatabase.InsertMeterManufactorData(tempMeterManufactor);

            MeterProtocolData tempMeterProtocol = new MeterProtocolData();
            int meterProtocolId = tempMeterProtocol.FillEmptyMeterProtocol();

            myDatabase.InsertMeterProtocolData(tempMeterProtocol);

            MeterTypeData tempMeterType = new MeterTypeData();
            int           meterTypeId   = tempMeterType.FillEmptyMeterType();

            myDatabase.InsertMeterTypeData(tempMeterType);

            MeterManagementData ADRESMeter = new MeterManagementData();

            ADRESMeter.SetCustomerId(customerId);
            ADRESMeter.SetManufactorId(meterManufactorId);
            ADRESMeter.SetProtolId(meterProtocolId);
            ADRESMeter.SetTypeId(meterTypeId);
            ADRESMeter.SetDescribtion("ADRES-01-01");
            ADRESMeter.SetKey("not availiable");
            ADRESMeter.SetPeriod(1);
            ADRESMeter.SetPort("not availiable");
            ADRESMeter.SetSerial("not availiable");
            ADRESMeter.SetActive(true);
            myDatabase.InsertMeterManagementData(ADRESMeter);

            this.ADRESMeterId = ADRESMeter.GetMeterId();
        }
Example #5
0
        protected override void fillDBWithMeters()
        {
            CustomerData tempCustomer = new CustomerData();
            int          customerId   = tempCustomer.FillEmptyCustomer();

            myDatabase.InsertCustomerData(tempCustomer);

            MeterManufactorData tempMeterManufactor = new MeterManufactorData();
            int meterManufactorId = tempMeterManufactor.FillEmptyMeterManufactor();

            myDatabase.InsertMeterManufactorData(tempMeterManufactor);

            MeterProtocolData tempMeterProtocol = new MeterProtocolData();
            int meterProtocolId = tempMeterProtocol.FillEmptyMeterProtocol();

            myDatabase.InsertMeterProtocolData(tempMeterProtocol);

            MeterTypeData tempMeterType = new MeterTypeData();
            int           meterTypeId   = tempMeterType.FillEmptyMeterType();

            myDatabase.InsertMeterTypeData(tempMeterType);

            ///Create whole houses meter
            for (int i = 0; i < 4; i++)
            {
                MeterManagementData UKDALEMeter = new MeterManagementData();
                UKDALEMeter.SetCustomerId(customerId);
                UKDALEMeter.SetManufactorId(meterManufactorId);
                UKDALEMeter.SetProtolId(meterProtocolId);
                UKDALEMeter.SetTypeId(meterTypeId);
                UKDALEMeter.SetDescribtion("UKDALE-" + i + "-ALL");
                UKDALEMeter.SetKey("not availiable");
                UKDALEMeter.SetPeriod(1);
                UKDALEMeter.SetPort("not availiable");
                UKDALEMeter.SetSerial("not availiable");
                UKDALEMeter.SetActive(true);
                myDatabase.InsertMeterManagementData(UKDALEMeter);

                int tempMeterId = UKDALEMeter.GetMeterId();

                Tuple <int, ApplicationEnum> temp;
                switch (i)
                {
                case 0:
                {
                    temp = new Tuple <int, ApplicationEnum>(tempMeterId, ApplicationEnum.UKDALEwholeHouse1);
                    break;
                }

                case 1:
                {
                    temp = new Tuple <int, ApplicationEnum>(tempMeterId, ApplicationEnum.UKDALEwholeHouse2);
                    break;
                }

                case 2:
                {
                    temp = new Tuple <int, ApplicationEnum>(tempMeterId, ApplicationEnum.UKDALEwholeHouse3);
                    break;
                }

                case 3:
                {
                    temp = new Tuple <int, ApplicationEnum>(tempMeterId, ApplicationEnum.UKDALEwholeHouse4);
                    break;
                }

                case 4:
                {
                    temp = new Tuple <int, ApplicationEnum>(tempMeterId, ApplicationEnum.UKDALEwholeHouse5);
                    break;
                }

                default:
                {
                    temp = new Tuple <int, ApplicationEnum>(tempMeterId, ApplicationEnum.None);
                    break;
                }
                }
                this.housesList.Add(temp);
            }

            String pathToUKDALEAplliances = "UKDaleAppliances\\";

            for (int i = 1; i <= 5; i++)
            {
                Console.WriteLine("working File: " + i);
                using (StreamReader file = new StreamReader(pathToUKDALEAplliances + "UKDALEdat_" + i + ".txt"))
                {
                    if (file != null)
                    {
                        String line = "";
                        while ((line = file.ReadLine()) != null)
                        {
                            MeterManagementData UKDALEMeter = new MeterManagementData();
                            UKDALEMeter.SetCustomerId(customerId);
                            UKDALEMeter.SetManufactorId(meterManufactorId);
                            UKDALEMeter.SetProtolId(meterProtocolId);
                            UKDALEMeter.SetTypeId(meterTypeId);

                            String[]        applicationParts     = line.Split(' ');
                            int             applicationNumber    = Int32.Parse(applicationParts[0]);
                            ApplicationEnum foundApplicationEnum = this.FindApplicationEnumByString(applicationParts[1]);

                            UKDALEMeter.SetDescribtion("UKDALE-" + (i - 1) + "-" + applicationNumber);
                            UKDALEMeter.SetKey("not availiable");
                            UKDALEMeter.SetPeriod(1);
                            UKDALEMeter.SetPort("not availiable");
                            UKDALEMeter.SetSerial("not availiable");
                            UKDALEMeter.SetActive(true);
                            myDatabase.InsertMeterManagementData(UKDALEMeter);

                            int tempMeterId = UKDALEMeter.GetMeterId();

                            int[] tempTupel = new int[2];
                            tempTupel[0] = tempMeterId;
                            tempTupel[1] = applicationNumber;

                            Tuple <int[], ApplicationEnum> temp = new Tuple <int[], ApplicationEnum>(tempTupel, foundApplicationEnum);

                            switch (i)
                            {
                            case 1:
                            {
                                this.house1ApplicationList.Add(temp);
                                break;
                            }

                            case 2:
                            {
                                this.house2ApplicationList.Add(temp);
                                break;
                            }

                            case 3:
                            {
                                this.house3ApplicationList.Add(temp);
                                break;
                            }

                            case 4:
                            {
                                this.house4ApplicationList.Add(temp);
                                break;
                            }

                            case 5:
                            {
                                this.house5ApplicationList.Add(temp);
                                break;
                            }
                            }
                        }
                    }
                }
            }
        }
Example #6
0
        private static int userInputDataset(List <IDataHandler> dataHandlerList)
        {
            int choice = 0;

            Console.WriteLine("Which Dataset do you want to load data from <1 ADRES | 2 GREEND | 3 REDD | 4 UKdale> ?");
            Console.WriteLine("Or do you want to <5 print meter_data | 6 Delete meter_data | 7 Delete all data | 8 Create completly new data");
            Console.WriteLine("Or do you want to <9 print customer data | 10 print meter management data | 11 print meter manufactor data");
            Console.WriteLine("Or do you want to <12 print meter protocol data | 13 print meter type data>");
            choice = getIntFromConsole();
            if (choice == 0)
            {
                return(1);
            }

            switch (choice)
            {
            case 1:
            {
                List <TypeEnum> tempTypeEnums = new List <TypeEnum>();
                //tempTypeEnums.Add(TypeEnum.Power);
                tempTypeEnums.Add(TypeEnum.Voltage);
                IDataHandler handler = new ADRESDataHandler(myDatabase, null, null, null, tempTypeEnums, 5);
                handler.setPath(@"E:\Anna\Dokumente\Studium\Jahr3\Semester5\BAC1\Lastprofile\ADRES\00originalData\umgewandelt");

                dataHandlerList.Add(handler);
                break;
            }

            case 2:
            {
                //IDataHandler handler = new GREENDDataHandler(myDatabase);
                //IDataHandler handler = new GREENDDataHandler(myDatabase, new DateTime(2013, 12, 06, 23, 55, 00), new DateTime(2013, 12, 06, 23, 56, 00));
                //IDataHandler handler = new GREENDDataHandler(myDatabase, new DateTime(2013, 12, 06, 23, 55, 00), new DateTime(2013, 12, 06, 23, 56, 00), null, null, 1);

                /*
                 * List<TypeEnum> tempEnumList = new List<TypeEnum>();
                 * tempEnumList.Add(TypeEnum.Current);
                 * tempEnumList.Add(TypeEnum.Power);
                 * IDataHandler handler = new GREENDDataHandler(myDatabase, new DateTime(2013, 12, 06, 23, 55, 00), new DateTime(2013, 12, 06, 23, 56, 00), null, tempEnumList, 1);
                 */

                /*
                 * List<TypeEnum> tempEnumList = new List<TypeEnum>();
                 * tempEnumList.Add(TypeEnum.Current);
                 * tempEnumList.Add(TypeEnum.Voltage);
                 * IDataHandler handler = new GREENDDataHandler(myDatabase, new DateTime(2013, 12, 06, 23, 55, 00), new DateTime(2013, 12, 06, 23, 56, 00), null, tempEnumList, 1);
                 */

                /*
                 * List<ApplicationEnum> tempApplicationList = new List<ApplicationEnum>();
                 * tempApplicationList.Add(ApplicationEnum.TV);
                 * tempApplicationList.Add(ApplicationEnum.WaterKettle);
                 * tempApplicationList.Add(ApplicationEnum.Radio);
                 * IDataHandler handler = new GREENDDataHandler(myDatabase, null, null, tempApplicationList, null, 1);
                 */

                List <ApplicationEnum> tempApplicationList = new List <ApplicationEnum>();
                tempApplicationList.Add(ApplicationEnum.TV);
                tempApplicationList.Add(ApplicationEnum.WaterKettle);
                tempApplicationList.Add(ApplicationEnum.Radio);
                IDataHandler handler = new GREENDDataHandler(myDatabase, new DateTime(2013, 12, 06, 23, 50, 00), new DateTime(2013, 12, 06, 23, 59, 59), tempApplicationList, null, 1);

                handler.setPath(@"E:\Anna\Dokumente\Studium\Jahr3\Semester5\BAC1\Lastprofile\GREEND_0-1_311014");

                dataHandlerList.Add(handler);
                break;
            }

            case 3:
            {
                IDataHandler           handler         = new REDDDataHandler(myDatabase);
                List <ApplicationEnum> tempApplication = new List <ApplicationEnum>();
                tempApplication.Add(ApplicationEnum.Dishwasher);
                handler.setPath(@"E:\Anna\Dokumente\Studium\Jahr3\Semester5\BAC1\Lastprofile\REDD");

                dataHandlerList.Add(handler);
                break;
            }

            case 4:
            {
                //IDataHandler handler = new UKdaleDataHandler(myDatabase);

                //IDataHandler handler = new UKdaleDataHandler(myDatabase, new DateTime(2013, 12, 06, 23, 55, 00), new DateTime(2013, 12, 06, 23, 56, 00));

                /*
                 * List<TypeEnum> tempEnumList = new List<TypeEnum>();
                 * tempEnumList.Add(TypeEnum.Current);
                 * tempEnumList.Add(TypeEnum.Voltage);
                 * IDataHandler handler = new UKdaleDataHandler(myDatabase, new DateTime(2013, 12, 06, 23, 55, 00), new DateTime(2013, 12, 06, 23, 56, 00), null, tempEnumList);
                 */

                /*
                 * List<TypeEnum> tempEnumList = new List<TypeEnum>();
                 * tempEnumList.Add(TypeEnum.Power);
                 * IDataHandler handler = new UKdaleDataHandler(myDatabase, new DateTime(2012, 11, 09, 23, 02, 21), new DateTime(2012, 11, 09, 23, 04, 21), null, tempEnumList);
                 */

                //IDataHandler handler = new UKdaleDataHandler(myDatabase, new DateTime(2013, 12, 06, 23, 55, 00), new DateTime(2013, 12, 06, 23, 56, 00), null, null, 1);

                /*
                 * List<TypeEnum> tempEnumList = new List<TypeEnum>();
                 * tempEnumList.Add(TypeEnum.Power);
                 * IDataHandler handler = new UKdaleDataHandler(myDatabase, new DateTime(2012, 11, 09, 23, 02, 21), new DateTime(2012, 11, 09, 23, 04, 21), null, tempEnumList, 1);
                 */

                List <ApplicationEnum> tempAppList = new List <ApplicationEnum>();
                tempAppList.Add(ApplicationEnum.WaterKettle);
                tempAppList.Add(ApplicationEnum.Laptop);
                List <TypeEnum> tempEnumList = new List <TypeEnum>();
                tempEnumList.Add(TypeEnum.Power);
                IDataHandler handler = new UKdaleDataHandler(myDatabase, new DateTime(2012, 11, 09, 23, 02, 21), new DateTime(2012, 11, 09, 23, 04, 21), tempAppList, tempEnumList, 1);

                handler.setPath(@"E:\Datasets\UK-DaleSample");


                dataHandlerList.Add(handler);
                break;
            }

            case 5:
            {
                myDatabase.PrintMeterData("");
                break;
            }

            case 6:
            {
                myDatabase.DeleteAllMeterData();
                break;
            }

            case 7:
            {
                myDatabase.DeleteAllMeterManagementData();
                myDatabase.DeleteAllMeterData();
                myDatabase.DeleteAllCustomerData();
                myDatabase.DeleteAllMeterManufactorData();
                myDatabase.DeleteAllMeterProtocolData();
                myDatabase.DeleteAllMeterTypeData();
                break;
            }

            case 8:
            {
                CustomerData tempCustomer = new CustomerData();
                int          customerId   = tempCustomer.FillEmptyCustomer();
                myDatabase.InsertCustomerData(tempCustomer);

                MeterManufactorData tempMeterManufactor = new MeterManufactorData();
                int meterManufactorId = tempMeterManufactor.FillEmptyMeterManufactor();
                myDatabase.InsertMeterManufactorData(tempMeterManufactor);

                MeterProtocolData tempMeterProtocol = new MeterProtocolData();
                int meterProtocolId = tempMeterProtocol.FillEmptyMeterProtocol();
                myDatabase.InsertMeterProtocolData(tempMeterProtocol);

                MeterTypeData tempMeterType = new MeterTypeData();
                int           meterTypeId   = tempMeterType.FillEmptyMeterType();
                myDatabase.InsertMeterTypeData(tempMeterType);

                MeterManagementData tempMeterManagement = new MeterManagementData();
                tempMeterManagement.FillEmptyManagementData(meterTypeId, meterProtocolId, meterManufactorId, customerId);
                myDatabase.InsertMeterManagementData(tempMeterManagement);
                break;
            }

            case 9:
            {
                myDatabase.PrintCustomerData("");
                break;
            }

            case 10:
            {
                myDatabase.PrintMeterManagementData("");
                break;
            }

            case 11:
            {
                myDatabase.PrintMeterManufactorData();
                break;
            }

            case 12:
            {
                myDatabase.PrintMeterProtocolData();
                break;
            }

            case 13:
            {
                myDatabase.PrintMeterTypeData();
                break;
            }
            }
            return(0);
        }