Ejemplo n.º 1
0
        //todo: refactor this savagery. viewers dont h8
        private static void AutomaticallySetRallyTime_Alpha(RallyBotConfig config, DateTime targetDate)
        {
            //required: must only autofill one week up to the target date (as to not appear suspicious under investigating)
            //required: support target date in order to backfill easily

            var week_begin_date = targetDate.AddDays(-(int)targetDate.DayOfWeek);
            var goal_concept    = string.Format("burn down hours from {0} to {1} as role: {2}", week_begin_date.ToString("MMMM dd yyyy"), targetDate.ToString("MMMM dd yyyy"), "dev");

            Console.WriteLine(goal_concept);

            //1. get tasks relating to this.user current task list on rally
            var db          = new RallyDatabase(config);
            var this_team   = db.GetTeamMembers(config.projectId);
            var my_id       = db.GetSpecificTeamMemberObjectId(this_team, config.username);
            var time_items  = db.GetTimeEntryItemsForOneTeamMember(my_id, week_begin_date); //todo: maybe class AWeekAtWork{list<timeitems>, computed int[] dailyHours, computed totalHours, method set priorities (orders list by given name list)}

            int daily_min   = config.hoursPerDay != 0 ? config.hoursPerDay : 8;
            int[] day_hours = new int[] { 0, 0, 0, 0, 0, 0, 0 };

            var priority_chart      = new Dictionary<string, TimeEntryItem>();
            var priority_strings    = new string[]{"Administration", "Regression", "Iteration Planning", "Deployment Planning", "Environment Issue", "User Stories"};

            Console.WriteLine(my_id             + " is my object_id");
            Console.WriteLine(time_items.Count  + " time entrys");
            Console.WriteLine("# # # # # # # # # # #");

            //this loop does 3 very different things. it fills the day_hours array, it establishes priorities, and generates a cli report
            foreach(TimeEntryItem item in time_items) {

                Console.WriteLine("Story Name: "+ item.self["WorkProductDisplayString"].ToString());
                Console.WriteLine("Task Name: " + item.self["TaskDisplayString"].ToString());
                Console.WriteLine("Time Values:\n");

                foreach(JToken time_value in item.timeEntryValues) {

                    var t_val_date = Convert.ToDateTime(time_value["DateVal"].ToString());
                    day_hours[(int)t_val_date.DayOfWeek] += (int)time_value["Hours"];

                    Console.WriteLine("DateVal: "       + ((string)time_value["DateVal"]).GetPrettyDate());
                    Console.WriteLine("Hours: "         + time_value["Hours"]);
                    Console.WriteLine("Last Updated: "  + time_value["LastUpdated"]);
                    Console.WriteLine("----------");
                }

                //needs to be after time calcs
                string priority_name = item.taskName.Contains(priority_strings, true);
                if(priority_name != string.Empty) {
                    if(!priority_chart.ContainsKey(priority_name)) {
                        priority_chart.Add(priority_name, item);
                    }
                }

                Console.WriteLine("==================================================\n\n\n");
            }

            //2. make sure that all the results are returned, should be about 77 for me
            //(ok good!)

            //3. find a formula that will determine how many hours i should have for the entire week up until the point/day i desire

            int required_hours = (int)targetDate.DayOfWeek * daily_min; //this will not support sunday work. maybe support weekend autofilling as a bool switch next version. also allow config of the 8 hours to more or less

            Console.WriteLine("min hours needed to pass inspection: " + required_hours);
            Console.WriteLine("You have " + day_hours.Sum() + " hours"); // if you do not match or exceed the min hours, then we will perform some autofilling

            //then add up the time for all days that week. if the total is less than sun-today * 8, then add new time entry values foreach day where total time < 8 (not in this method fyi)

            //consider while here while() TODO: instead of doing the submints in this loop. just generate a workload to perform later
            if (day_hours.Sum() < required_hours) {

                for(int i = 0; i<day_hours.Length; ++i) {

                    int this_days_time  = day_hours[i];
                    string day_name     = Enum.GetName(typeof(DayOfWeek), i);
                    int time_needed     = daily_min - this_days_time; //this allows for overages since we are adding in increments of 8. should only allow for a maximum of (inspection_amount + increment-1)
                    int week_total_hours= day_hours.Sum();//important to refresh each loop

                    if (week_total_hours < required_hours && time_needed > 0 /**/ && i!=0 && i !=6) { //hard code ignore of sunday and saturaday for now