Exemplo n.º 1
0
 public Model()
 {
     ts = null;
     seasonal = null;
     values = null;
     errors = null;
 }
Exemplo n.º 2
0
 static void Main(string[] args)
 {
     ITimeControlledObject model = new Model();
     for (uint i = 0; i < c_uNumIterations; i++)
     {
         model.Trigger();
     }
     Console.ReadLine();
 }
Exemplo n.º 3
0
        public Model(TimeSeries ts)
        {
            this.ts = ts;
            seasonal = null;
            values = null;
            errors = null;

            ModelType best = ModelType.Trend;
            double min = double.MaxValue;
            foreach (ModelType t in Enum.GetValues(typeof(ModelType)))
            {
                this.type = t;
                this.Solve();
                this.CalcError();
                double rt = this.Size() * Error(0.9);
                if (min > rt) { min = rt; best = t; }
            }
            this.type = best;
            this.Solve();
            this.CalcError();
            this.len = ts.Length;
        }
Exemplo n.º 4
0
        public void getModels(int len, double error, ref int length)
        {
            length = 0;
            int kk = (int)Math.Floor((double)ts.Length / len);

            models = new Model[kk];
            int x = 0;
            this.len = len;
            for (int i = 0; i < kk; i++)
            {
                if (i == kk - 1) len = ts.Length - x;

                double[] u = new double[len];
                for (int j = 0; j < len; j++) u[j] = ts.data[x++];
                TimeSeries t = new TimeSeries(u, ts.freq);
                Model m = new Model(t);
                length += m.countError(error);
                models[i] = m;
            }
        }
Exemplo n.º 5
0
        public void Solve()
        {
            int n = ts.Length;
            if ((ts.freq == null))
            {
                // ts data is used
                int x = 9;
                x++;
            }
            else
            {
                int freq = ts.freq[0];
                int l = 0;
                while (freq > ts.Length) { freq = ts.freq[l++]; }
                if (freq == 0)
                {
                    //use regression
                    values = ChebyshevReg.Solve(ts.data);
                    seasonal = null;
                }
                else
                {
                    double[] season_ = new double[freq];

                    decompose(n, freq, season_);
                    this.freq = freq;
                    seasonal = new Model();
                    int[] f;
                    if (ts.freq.Length == 1) f = null;
                    else
                    {
                        f = new int[ts.freq.Length - 1];
                        for (int i = 0; i < ts.freq.Length - 1; i++) f[i] = ts.freq[i + 1];
                    }
                    seasonal.ts = new TimeSeries(season_, f);

                    if (f != null)
                        seasonal.Solve();
                }
            }
        }
Exemplo n.º 6
0
        /*
        public void LoadInFile()
        {
            Sports.Add(new Sport { Name = "qwe" });
            DataContractSerializer dcs = new DataContractSerializer(typeof(Model));
            StringBuilder sb = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(sb);
            dcs.WriteObject(writer, this);
            writer.Close();
            string xml = sb.ToString();
            XDocument.Parse(xml).Save("data.xml");

            SaveBinaryFormat(this, "dd.xml");
        }*/
        /// <summary>
        /// Сериализация данных в бинарных файл
        /// </summary>
        /// <param name="model">Модель данных</param>
        /// <param name="fileName">Имя файла</param>
        public static void SaveBinaryFormat(Model model, string fileName)
        {
            BinaryFormatter binFormat = new BinaryFormatter();
            using (Stream fStream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                binFormat.Serialize(fStream, model);
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            var text = File.ReadAllText(args.First());
            var segments = Segment.Parse(text);

            var model = new Model();

            (new ModelSegmentWalker(model) as ISegmentWalker).Walk(segments);

            var builder = new ContainerBuilder();
            builder.RegisterInstance(model);
            var container = builder.Build();

            var config = new BusConfiguration();
            config.UseContainer<AutofacBuilder>(c => c.ExistingLifetimeScope(container));

            using (var bus = Bus.CreateSendOnly(config))
            {
                var messageSender = container.Resolve<ISendMessages>();

                foreach (var conversation in model.Conversations)
                {
                    Console.WriteLine(conversation.Name);
                    var conversationId = Guid.NewGuid();

                    foreach (var m in conversation.Messages)
                    {
                        var tm = new TransportMessage();
                        tm.Headers[Headers.MessageId] = m.MessageId;
                        tm.Headers[Headers.ConversationId] = conversationId.ToString();
                        tm.Headers[Headers.EnclosedMessageTypes] = m.MessageType;
                        tm.Headers[Headers.RelatedTo] = m.RelatedTo;
                        tm.Headers[Headers.MessageIntent] = m.Intent;
                        tm.Headers[Headers.OriginatingEndpoint] = m.Sender;
                        tm.Headers[Headers.OriginatingMachine] = "MACHINE";
                        tm.Headers[Headers.TimeSent] = ToWireFormattedString(DateTime.Now);

                        tm.Headers[Headers.ProcessingEndpoint] = m.Receiver;
                        tm.Headers[Headers.ProcessingMachine] = "MACHINE";
                        tm.Headers[Headers.ProcessingStarted] = ToWireFormattedString(DateTime.Now);
                        tm.Headers[Headers.ProcessingEnded] = ToWireFormattedString(DateTime.Now);

                        if (m.Intent == "Timeout")
                        {
                            tm.Headers[Headers.MessageIntent] = "Send";
                            tm.Headers[Headers.IsDeferredMessage] = "true";
                            tm.Headers[Headers.IsSagaTimeoutMessage] = "true";
                        }

                        var outQueue = "audit";
                        if (m.Intent == "Error")
                        {
                            outQueue = "error";
                            tm.Headers["NServiceBus.ExceptionInfo.ExceptionType"] = typeof(Exception).FullName;
                            tm.Headers["NServiceBus.ExceptionInfo.Message"] = "There was an error.";
                            tm.Headers["NServiceBus.FailedQ"] = $"{m.Sender}@MACHINE";
                            tm.Headers["NServiceBus.TimeOfFailure"] = ToWireFormattedString(DateTime.Now);
                        }

                        Console.WriteLine($"\t {m.Intent} {m.MessageType} from {m.Sender} to {m.Receiver}");
                        messageSender.Send(tm, new SendOptions(Address.Parse(outQueue)));
                    }
                }
            }
        }