示例#1
0
文件: Program.cs 项目: ohadmanor/TDS
        static void addAtomsToRoute(Route route, AtomGenerator generator, int count)
        {
            for (int i = 0; i < count; i++)
            {
                double scatterLength = 0.0000;
                double offset = Util.rand.NextDouble();

                double firstLegDeltaX = route.routePoints[1].x - route.routePoints[0].x;
                double firstLegDeltaY = route.routePoints[1].y - route.routePoints[0].y;

                double length = Math.Sqrt(firstLegDeltaX * firstLegDeltaX + firstLegDeltaY * firstLegDeltaY);

                double scatterX = (scatterLength / length) * firstLegDeltaX;
                double scatterY = (scatterLength / length) * firstLegDeltaY;

                AtomObject atom = new AtomObject(route.name + i, 0, route.routePoints[0].x - scatterX*offset, route.routePoints[0].y - scatterY*offset);

                // generate new random number for start time - for now between 0:01 to 1:30
                int minutes = Util.rand.Next(2);
                int seconds = Util.rand.Next(1, 60);
                int speed = Util.rand.Next(3, 11);

                String secondsString = seconds >= 10 ? seconds.ToString() : "0" + seconds;
                Activity activity = new Activity(100 + i, atom.guid, 1, 1, "00:0" + minutes + ":" + secondsString,
                                                 "00:00:01", speed, route.guid, route.routePoints[0].x, route.routePoints[0].y);
                generator.createAtom(atom);
                generator.createActivityToAtom(activity, atom);
                generator.addAtomToTreeObject(atom);
            }
        }
示例#2
0
        public void createActivityToAtom(Activity activity, AtomObject atom)
        {
            // TODO - read from sequence

            String query = "INSERT INTO activites(activityid, atom_guid, activity_seqnumber, activitytype,"
                + " startactivityoffset, durationactivity, speed, route_guid, referencepointx, referencepointy)"
                + " VALUES (:id, :atomGuid, :activitySeq, :activityType, :startOffset, :duration, :speed, :routeGuid, :refX, :refY)";
            NpgsqlCommand command = new NpgsqlCommand(query, connection);
            command.Parameters.Add(new NpgsqlParameter("id", activity.activityId));
            command.Parameters.Add(new NpgsqlParameter("atomGuid", activity.atomGuid));
            command.Parameters.Add(new NpgsqlParameter("activitySeq", activity.activitySeqNumber));
            command.Parameters.Add(new NpgsqlParameter("activityType", activity.activityType));
            command.Parameters.Add(new NpgsqlParameter("startOffset", activity.startActivityOffset));
            command.Parameters.Add(new NpgsqlParameter("duration", activity.durationActivity));
            command.Parameters.Add(new NpgsqlParameter("speed", activity.speed));
            command.Parameters.Add(new NpgsqlParameter("routeGuid", activity.routeGuid));
            command.Parameters.Add(new NpgsqlParameter("refX", activity.refX));
            command.Parameters.Add(new NpgsqlParameter("refY", activity.refY));
            command.ExecuteNonQuery();

            // TODO - increment seuquence
        }