Esempio n. 1
0
    void LoadAllRoomData()
    {
        //these need to be in the room data folder:
        //TextAsset data1 = Resources.Load ("RoomData/"roomNames [0]) as TextAsset;
        //TextAsset data2 = Resources.Load ("RoomData/"roomNames [1]) as TextAsset;

        datas = Resources.LoadAll <TextAsset> ("RoomData");

        int num = datas.Length;

        print("This many text assets were loaded: " + datas.Length);
        arrayofRmsTemps = new IaTemperature[num][];
        for (int i = 0; i < num; i++)
        {
            string   inputx = datas [i].text;
            string[] linesx = inputx.Split(new[] { '\r', '\n' }, System.StringSplitOptions.RemoveEmptyEntries);
            int      q      = linesx.Length - 1;
            //there are the same number of events as number of lines subtracting the header
            arrayofRmsTemps [i] = new IaTemperature[q];
            //roomTemps = new IaTemperature[q];
            Debug.Log("number of datapoints in room " + datas [i].name + " array: " + arrayofRmsTemps [i].Length);
            for (int o = 1; o <= q; o++)
            {
                string[] col  = linesx [o].Split(new[] { ',' });
                float    temp = -100;
                try {
                    temp = Convert.ToSingle(col [2]);
                }
                catch (FormatException) {
                    Debug.Log("Problem converting column temp for line " + (o + 1) + ". Check data");
                }
                catch (OverflowException) {
                    Debug.Log("overflow");
                }
                DateTime newTime = DateTime.Parse(col [0], provider);
                arrayofRmsTemps [i] [o - 1] = new IaTemperature(roomNames [i], newTime, temp, false);

                //for the first instance of timestamp we want to set it to current, or if the previous datapoint had an error in the temp reading
                //for every instance of our array of temps for the room want to compare it with the previous to see if it has a greater time (works with ascending data)
                if (o == 1 || arrayofRmsTemps [i] [o - 2].temperature == -100)
                {
                    arrayofRmsTemps [i] [o - 1].isCurrent = true;
                }
                else
                if (arrayofRmsTemps [i] [o - 1].timestamp > arrayofRmsTemps [i] [o - 2].timestamp)
                {
                    arrayofRmsTemps [i] [o - 1].isCurrent = true;
                    arrayofRmsTemps [i] [o - 2].isCurrent = false;
                }
                //if we set this temp to be most current, unset the last one as current. (works with decending data)
                if (arrayofRmsTemps [i] [o - 1].isCurrent == true)
                {
                    if (o > 1)
                    {
                        arrayofRmsTemps [i] [o - 2].isCurrent = false;
                    }
                }
                //debug which line has what values
                //print(roomTemps[i-1].ToString());

                //debug which line has what values
                //print (arrayofRmsTemps [i] [o - 1].ToString ());
            }
        }
    }
Esempio n. 2
0
    //for only the string roomName
    void LoadRoomName()
    {
        data = Resources.Load(roomName) as TextAsset;
        string input = data.text;

        string[] lines = input.Split(new[] {
            '\r',
            '\n'
        }, System.StringSplitOptions.RemoveEmptyEntries);
        int p = lines.Length - 1;

        //there are the same number of events as number of lines subtracting the header
        roomTemps = new IaTemperature[p];
        Debug.Log("number of datapoints in room " + roomName + " array: " + roomTemps.Length);
        //adjust to remove the header from the sequence...
        for (int i = 1; i <= p; i++)
        {
            string[] col = lines [i].Split(new[] {
                ','
            });
            //set temp to some value which shows there is an error in reading:
            float temp = -100;
            //sets the inside air temp of room 1001 for the first three columns
            //cast column 3 as float
            try {
                temp = Convert.ToSingle(col [2]);
            }
            catch (FormatException) {
                Debug.Log("Problem converting column temp for line " + (i + 1) + ". Check data");
            }
            catch (OverflowException) {
                Debug.Log("overflow");
            }
            //lets try to create a DateTime instead of double in OA format (works but using culture info to understand nz time source)
            //DateTime newTime = DateTime.FromOADate(time);
            //Debug.Log ("at line " + (i + 1) + " we have a DateTime value " + newTime + " associated with " + time);
            DateTime newTime = DateTime.Parse(col [0], provider);
            //check if datetime is associated correctly and reading correctly
            //Debug.Log ("at line " + (i +1) + " we have a DateTime value " + newTime + " associated with " + col[0]);
            roomTemps [i - 1] = new IaTemperature(roomName, newTime, temp, false);
            //still have compressor, fans, occupancy, and scheduled available and unused
            //for the first instance of timestamp we want to set it to current, or if the previous datapoint had an error in the temp reading
            //for every instance of our array of temps for the room want to compare it with the previous to see if it has a greater time (works with ascending data)
            if (i == 1 || roomTemps [i - 2].temperature == -100)
            {
                roomTemps [i - 1].isCurrent = true;
            }
            else
            if (roomTemps [i - 1].timestamp > roomTemps [i - 2].timestamp)
            {
                roomTemps [i - 1].isCurrent = true;
                roomTemps [i - 2].isCurrent = false;
            }
            //if we set this temp to be most current, unset the last one as current. (works with decending data)
            if (roomTemps [i - 1].isCurrent == true)
            {
                if (i > 1)
                {
                    roomTemps [i - 2].isCurrent = false;
                }
            }
            //debug which line has what values
            //print(roomTemps[i-1].ToString());
        }
    }