예제 #1
0
파일: Program.cs 프로젝트: dhakalsamip/LoT
        private static void Write(IStream stream)
        {
            try
            {
                int    i  = 1;
                StrKey k1 = k1 = new StrKey("k1");
                while (true)
                {
                    stream.Append(k1, new ByteValue(StreamFactory.GetBytes("k1-value" + i)));
                    i++;

                    Console.WriteLine("Written " + i + " values");
                    if (i % 10 == 0)
                    {
                        stream.Seal(false);
                    }


                    if (isWriting)
                    {
                        System.Threading.Thread.Sleep(1000);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception in write: " + e);
            }
        }
예제 #2
0
        public void ReadObject()
        {
            long start = DateTime.Now.Ticks;

            for (int i = 0; i < numberOfStreams; i++)
            {
                dataStreams.ElementAt(i).Append(new StrKey("ID"), new ByteValue(BitConverter.GetBytes(count)), count);
                dataStreams.ElementAt(i).Append(new StrKey("Type"), new ByteValue(StreamFactory.GetBytes(types[count % types.Length])), count);
                dataStreams.ElementAt(i).Append(new StrKey("EnterTimestamp"), new ByteValue(BitConverter.GetBytes(94.00000)), count);
                dataStreams.ElementAt(i).Append(new StrKey("ExitTimestamp"), new ByteValue(BitConverter.GetBytes(231.00000)), count);
                dataStreams.ElementAt(i).Append(new StrKey("EntryArea"), new ByteValue(BitConverter.GetBytes(2)), count);
                dataStreams.ElementAt(i).Append(new StrKey("ExitArea"), new ByteValue(BitConverter.GetBytes(1)), count);
                List <int> l = new List <int>()
                {
                    114, 114, 117, 121, 134, 133, 141, 115, 136, 129, 127, 120, 138, 130, 128, 126, 121, 129, 123, 127, 120, 121, 121, 131, 132, 117, 136, 126, 131, 127, 133, 133, 129, 128, 115, 137, 128, 125, 120, 129, 134, 128, 129, 130, 127, 133, 128, 126, 133, 130, 122, 127, 128, 121, 126, 129, 130, 122, 123, 127, 134, 121, 126, 135, 132, 123, 134, 126, 129, 124, 134, 131, 130, 124
                };
                dataStreams.ElementAt(i).Append(new StrKey("SMPC"), new ByteValue(l.SelectMany(BitConverter.GetBytes).ToArray()), count);
            }
            long time = DateTime.Now.Ticks - start;

            using (writer = File.AppendText(outputFilePath))
                writer.Write(count + "," + time);
            Console.Write(count + "," + time);
            count++;
        }
예제 #3
0
 public void DirStreamTest_TestUpdateByteValue()
 {
     dds_byte_val = streamFactory.openFileDataStream <StrKey>(streamID, callerInfo, locationInfo, streamSecurityType, CompressionType.None, StreamFactory.StreamOp.Write);
     dds_byte_val.Update(k1, new ByteValue(StreamFactory.GetBytes("k1-cmu")));
     dds_byte_val.Update(k2, new ByteValue(StreamFactory.GetBytes("k2-msr")));
     dds_byte_val.Update(k1, new ByteValue(StreamFactory.GetBytes("k1-msr")));
 }
예제 #4
0
 public void SyncFileStreamTest_TestRepeatedClose()
 {
     for (int i = 0; i < 10; ++i)
     {
         StreamFactory sf           = StreamFactory.Instance;
         IStream       dfs_byte_val = sf.openValueDataStream <StrKey, ByteValue>(new FqStreamID("99-2729", "A0", "TestMultiClose"),
                                                                                 new CallerInfo(null, "A0", "A0", 1),
                                                                                 locationInfo,
                                                                                 StreamFactory.StreamSecurityType.Plain,
                                                                                 CompressionType.None,
                                                                                 StreamFactory.StreamOp.Write);
         dfs_byte_val.Append(k1, new ByteValue(StreamFactory.GetBytes("k1-cmu-" + i)));
         dfs_byte_val.Close();
         Thread.Sleep(5000);
     }
 }
 public void LocalListedValueDataStreamTest_TestUpdateByteValue()
 {
     vds.Append(k1, new ByteValue(StreamFactory.GetBytes("k1-cmu")));
     vds.Append(k2, new ByteValue(StreamFactory.GetBytes("k2-msr")));
     vds.Append(k1, new ByteValue(StreamFactory.GetBytes("k1-msr")));
 }
예제 #6
0
파일: HDS_Test.cs 프로젝트: dhakalsamip/LoT
        static void Main(string[] args)
        {
            string       AzureaccountName = ConfigurationManager.AppSettings.Get("AccountName");
            string       AzureaccountKey  = ConfigurationManager.AppSettings.Get("AccountSharedKey");
            LocationInfo li = new LocationInfo(AzureaccountName, AzureaccountKey, SynchronizerType.Azure);

            /*
             * string dataFile = "D:\\b";
             * int KB = 1024;
             * int[] chunk_sizes = { 4*1024*KB , 8*1024*KB };
             *
             * for (int i = 1; i <= 1; i++)
             * {
             *  for (int threads = 1; threads <= 1; threads++)
             *  {
             *      foreach (int csize in chunk_sizes)
             *      {
             *          Console.Write(">");
             *          File.Copy(dataFile, dataFile + threads + "," + csize);
             *
             *          AzureHelper helper = new AzureHelper(AzureaccountName, AzureaccountKey, "foo123123", CompressionType.None, EncryptionType.None, null, null, new Logger(), csize, threads);
             *          long start = DateTime.Now.Ticks;
             *          helper.UploadFileAsChunks(dataFile + threads + "," + csize);
             *          long end = DateTime.Now.Ticks;
             *          Console.WriteLine(threads + "," + csize + "," + (((double)(end - start) / (double)10000000)) );
             *      }
             *
             *  }
             * }
             */



            li = null;
            FqStreamID fq_sid = new FqStreamID("1299-2716", "A", "TestBS");
            CallerInfo ci     = new CallerInfo(null, "A", "A", 1);

            StreamFactory sf = StreamFactory.Instance;

            sf.deleteStream(fq_sid, ci);

            IStream dfs_byte_val = sf.openValueDataStream <StrKey, ByteValue>(fq_sid, ci, li,
                                                                              StreamFactory.StreamSecurityType.Plain,
                                                                              CompressionType.None,
                                                                              StreamFactory.StreamOp.Write);

            StrKey k1 = new StrKey("k1");

            dfs_byte_val.Append(k1, new ByteValue(StreamFactory.GetBytes("k1-cmu")));
            dfs_byte_val.Append(k1, new ByteValue(StreamFactory.GetBytes("k1-msr")));

            dfs_byte_val.Seal(false);
            dfs_byte_val.Append(k1, new ByteValue(StreamFactory.GetBytes("k1-uw")));

            dfs_byte_val.Close();
            Console.ReadKey();


            dfs_byte_val = sf.openValueDataStream <StrKey, ByteValue>(fq_sid, ci, li,
                                                                      StreamFactory.StreamSecurityType.Plain,
                                                                      CompressionType.None,
                                                                      StreamFactory.StreamOp.Write);


            Console.WriteLine("Get in read : " + dfs_byte_val.Get(k1));
            IEnumerable <IDataItem> data = dfs_byte_val.GetAll(k1, 0, StreamFactory.NowUtc());

            foreach (IDataItem dataItem in data)
            {
                Console.WriteLine(dataItem.GetVal().ToString());
            }

            dfs_byte_val.Close();
            Console.ReadKey();

            /*
             * ValueSerializerBase<StrKey> vsb = new ValueSerializerBase<StrKey>();
             * Byte[] buffer1 = vsb.SerializeToByteStream().ToArray();
             * Byte[] buffer2 = SerializerHelper<StrKey>.SerializeToProtoStream(k1).ToArray();
             *
             * FileStream fout = new FileStream("tmp.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);
             * BinaryWriter fs_bw = new BinaryWriter(fout);
             * fs_bw.Write(buffer1);
             * fs_bw.Write("-----W00t!-----");
             * fs_bw.Write(buffer2);
             * fs_bw.Write("-----W00t!-----");
             * fs_bw.Close();
             * fout.Close();
             */
        }
예제 #7
0
 public void ValueDataStreamTest_TestUpdateByteValue()
 {
     dfs_byte_val.Update(k1, new ByteValue(StreamFactory.GetBytes("k1-cmu")));
     dfs_byte_val.Update(k2, new ByteValue(StreamFactory.GetBytes("k2-msr")));
     dfs_byte_val.Update(k1, new ByteValue(StreamFactory.GetBytes("k1-msr")));
 }
예제 #8
0
        public List <RetVal> PredictOccupancy(long startSlotIndex, long endSlotIndex)
        {
            List <RetVal> retVal = new List <RetVal>();

            System.IO.StreamReader datafile = null;

            if (dataFilePath != null) //assuming datafile has one occupancy value per line read to startSlotIndex
            {
                string line;
                int    counter = 0;
                datafile = new System.IO.StreamReader(this.dataFilePath);
                if (startSlotIndex != 0)
                {
                    while ((line = datafile.ReadLine()) != null)
                    {
                        if (counter == startSlotIndex)
                        {
                            break;
                        }
                        counter++;
                    }
                }
            }

            StreamFactory streamFactory = StreamFactory.Instance;

            FqStreamID fq_sid = new FqStreamID("preheatnaive", "A", "TestBS");
            CallerInfo ci     = new CallerInfo(null, "A", "A", 1);

            streamFactory.deleteStream(fq_sid, ci);
            IStream occupancyGroundTruthStream = streamFactory.openValueDataStream <StrKey, ByteValue>(fq_sid, ci, null, StreamFactory.StreamSecurityType.Plain, CompressionType.None, StreamFactory.StreamOp.Write, null, 4 * 1024 * 1024, 1, new Logger());

            int slotIndex = 0; long startTime, retrievelTime, computeTime, appendTime;

            while (true)
            {
                startTime = DateTime.Now.Ticks;
                List <int>         currentPOV      = ConstructCurrentPOV(occupancyGroundTruthStream, slotIndex);
                List <List <int> > previousDaysPOV = ConstructPreviousPOV(occupancyGroundTruthStream, slotIndex);
                retrievelTime = DateTime.Now.Ticks - startTime;

                startTime = DateTime.Now.Ticks;
                int predictedOccupancy = Predict(currentPOV, previousDaysPOV);

                computeTime = DateTime.Now.Ticks - startTime;

                startTime = DateTime.Now.Ticks;
                if (datafile == null) // if no datafile to read the ground truth from just append randomly
                {
                    occupancyGroundTruthStream.Append(occupancyKey, new ByteValue(BitConverter.GetBytes(random.Next(2))), slotIndexBase + slotIndex);
                }
                else
                {
                    string line = datafile.ReadLine();
                    if (line == null)
                    {
                        Console.WriteLine("reached the end of datafile");
                        break;
                    }
                    occupancyGroundTruthStream.Append(occupancyKey, new ByteValue(StreamFactory.GetBytes(line)), slotIndexBase + slotIndex);
                }
                slotIndex++;
                appendTime = DateTime.Now.Ticks - startTime;

                Console.WriteLine("Slot number {0} {1} {2} {3}", slotIndex, retrievelTime, computeTime, appendTime);
                using (results = File.AppendText(outputFilePath))
                    results.WriteLine("Slot number {0} {1} {2} {3}", slotIndex, retrievelTime, computeTime, appendTime);
                //retVal.Add(new RetVal(endTime - startTime, predictedOccupancy));

                if (slotIndex == endSlotIndex)
                {
                    break;
                }
            }
            occupancyGroundTruthStream.Close();
            return(retVal);
        }