Example #1
0
 private void DeleteNote(int noteId)
 {
     using (UaFootball_DBDataContext db = DBManager.GetDB())
     {
         MatchNote noteToDelete = db.MatchNotes.SingleOrDefault(mn => mn.MatchNote_Id == noteId);
         if (noteToDelete != null)
         {
             db.MatchNotes.DeleteOnSubmit(noteToDelete);
         }
         db.SubmitChanges();
     }
 }
        //Accept the parent index as a parameter to allow for recursave calls
        public static void Process_Note_Range(int last_note_index, int? last_DT_index, 
            note_node parent_node_, MatchNote currentMatchNote, 
            int cost_limit, int max_end_notes, CancellationToken cts)
        {
            Logging.Update_note_position(parent_node_.NoteDetails.position);
            //Logging.Update_Status("Processing Notes for parent:" + parent_node_.ToString());

            /* Start the loop at the current index position and work forwards through the
                note results untill the next note position is found
             */

            //try
            //{

            //Get ordered list

            List<MatchNote> MatchLoop = MatchNotes.getNextMatchNotes(currentMatchNote);
            if (MatchLoop == null)
            {
                //No more notes left so finish
                return;
            }

            //First pass of maatching note, calculate cost and add to the BestNodes
            foreach (MatchNote tempMatchNote in MatchLoop)
            {

                int i = 0;
                // Current note note is 'next' in the position then add the current note to the DT

                note_node new_node = new note_node(last_DT_index, last_note_index, i, tempMatchNote, parent_node_);
                new_node.cost = CostCalculator.get_note_cost2(new_node, parent_node_);

                BestNodes.add_Node(new_node);// Need to add the note node to the best nodes incase the position is currently empty
                int costcomp = BestNodes.compare_Cost(new_node);
                if (i <= cost_limit)
                {
                    DecisionTree.add_node(new_node);

                }
            }

            //Get a list of the new DT Nodes order by lowest cost first
            List<note_node> Note_Nodes_list = DecisionTree.get_Children(parent_node_)
                .OrderBy(p => p.cost)
                .ToList();

            // Next loop though the newly created DT Nodes with the parent
            foreach (note_node temp_node in Note_Nodes_list)
            {
                int i;
                //Check the cost comparison is less than or = to the current best node
                //if yes then add to the DT & cotinue to process the notes children
                i = BestNodes.compare_Cost(temp_node);
                if (i <= cost_limit)
                {

                    //If not the last note in
                    if (temp_node.NoteDetails.last_note == false)
                    {

                        if (cts.IsCancellationRequested || currentEndCount_ == max_end_notes)
                        {
                            return;
                        }

                        // DANGER !!!! This is a stab in the dark approach to sort the bigger problem regards
                        // total processing time
                        if (temp_node.NoteDetails.position == MatchNotes.get_last_note_position())
                        {
                            currentEndCount_ += 1;
                            Logging.Update_Status("End note found :" + currentEndCount_.ToString());
                            return;

                        }

                        Process_Note_Range(i, temp_node.tree_index, temp_node, temp_node.NoteDetails,
                            cost_limit, max_end_notes, cts);

                    }
                }

                else
                    temp_node.Excluded = true;

            }
        }
Example #3
0
        public void CopyDTOToDbObject(MatchDTO dtoObj, Match dbObj)
        {
            dbObj.AwayClub_Id         = dtoObj.AwayClub_Id;
            dbObj.AwayNationalTeam_Id = dtoObj.AwayNationalTeam_Id;
            dbObj.AwayPenaltyScore    = dtoObj.AwayPenaltyScore;
            dbObj.AwayScore           = dtoObj.AwayScore;
            dbObj.Competition_Id      = dtoObj.Competition_Id;
            dbObj.CompetitionStage_Id = dtoObj.CompetitionStage_Id;
            dbObj.Date                = dtoObj.Date;
            dbObj.HomeClub_Id         = dtoObj.HomeClub_Id;
            dbObj.HomeNationalTeam_Id = dtoObj.HomeNationalTeam_Id;
            dbObj.HomePenaltyScore    = dtoObj.HomePenaltyScore;
            dbObj.HomeScore           = dtoObj.HomeScore;
            dbObj.Match_Id            = dtoObj.Match_Id;
            dbObj.Referee_Id          = dtoObj.Referee == null ? null : (int?)dtoObj.Referee.Referee_Id;
            dbObj.Season_Id           = dtoObj.Season_Id;
            dbObj.Spectators          = dtoObj.Spectators;
            dbObj.Stadium_Id          = dtoObj.Stadium.Stadium_ID;
            dbObj.Spectators          = dtoObj.Spectators;
            dbObj.Flags               = dtoObj.Flags;
            dbObj.SpecialNote         = dtoObj.SpecialNote;
            dbObj.AdminNotes          = dtoObj.AdminNotes;
            dbObj.Sources             = dtoObj.Sources;

            foreach (MatchLineupDTO l in dtoObj.Lineup)
            {
                if ((l.MatchLineup_Id > 0) && dbObj.MatchLineups.Any(ml => ml.MatchLineup_Id == l.MatchLineup_Id))  //update existing record
                {
                    MatchLineup mlToUpdate = dbObj.MatchLineups.Single(ml => ml.MatchLineup_Id == l.MatchLineup_Id);
                    l.CopyDTOToDbObject(mlToUpdate);
                }
                else //add new record
                {
                    if (l.Player_Id > 0 || l.CoachId > 0)
                    {
                        MatchLineup mlToAdd = new MatchLineup();
                        l.CopyDTOToDbObject(mlToAdd);
                        dbObj.MatchLineups.Add(mlToAdd);
                    }
                }
            }

            foreach (MatchEventDTO e in dtoObj.Events)
            {
                if ((e.MatchEvent_Id > 0) && dbObj.MatchEvents.Any(me => me.MatchEvent_Id == e.MatchEvent_Id))
                {
                    MatchEvent meToUpdate = dbObj.MatchEvents.Single(me => me.MatchEvent_Id == e.MatchEvent_Id);
                    e.CopyDTOToDbObject(meToUpdate);
                }
                else
                {
                    MatchEvent eToAdd = new MatchEvent();
                    e.CopyDTOToDbObject(eToAdd);
                    dbObj.MatchEvents.Add(eToAdd);
                }
            }

            foreach (MatchNoteDTO note in dtoObj.Notes)
            {
                MatchNote noteToAdd = new MatchNote {
                    Code = note.Code, Text = note.Text
                };
                dbObj.MatchNotes.Add(noteToAdd);
            }
        }
        //Accept the parent index as a parameter to allow for recursave calls
        public static void Process_Note_Range(int last_note_index, int? last_DT_index, note_node parent_node_, MatchNote currentMatchNote, int cost_limit, CancellationToken cts)
        {
            Logging.Update_note_position(parent_node_.NoteDetails.position);
            //Logging.Update_Status("Processing Notes for parent:" + parent_node_.ToString());

            /* Start the loop at the current index position and work forwards through the
                note results untill the next note position is found
             */

            //try
            //{
            if (parent_node_.NoteDetails.last_note == true)
            {
                //Logging.Update_Status("End note found!");
                return;
            }
            List<MatchNote> MatchLoop = MatchNotes.getNextMatchNotes(currentMatchNote);
            if (MatchLoop == null)
            {
                //No more notes left
                return;
            }

            foreach (MatchNote tempMatchNote in MatchLoop)
            {

                int i = 0;
                // Current note note is 'next' in the position then add the current note to the DT

                //TODO Extract Add note from Decision tree to allow cost evaluation before tree has
                // an added value
                note_node new_node = new note_node(last_DT_index, last_note_index, i, tempMatchNote, parent_node_);
                new_node.cost = CostCalculator.get_note_cost2(new_node, parent_node_);

                i = BestNodes.compare_Cost(new_node);
                BestNodes.add_Node(new_node);// Need to add the note node to the best nodes incase the position is currently empty

                //Check the cost comparison is less than or = to the current best node
                //if yes then add to the DT & cotinue to process the notes children
                if (i <= cost_limit)
                {

                    DecisionTree.add_node(new_node);

                    //If not the last note in
                    if (tempMatchNote.last_note == false)
                    {

                        if (cts.IsCancellationRequested)
                        {
                            return;
                        }

                        // If not the last note position then perform recursive call to generate the next tree node
                        //await Task.Run(() => Process_Note_Range(i, new_node.tree_index, new_node, tempMatchNote, cost_limit, cts), cts);
                        Process_Note_Range(i, new_node.tree_index, new_node, tempMatchNote, cost_limit, cts);
                        // Finished processing of the note to break from the loop
                    }
                }

            }

            //            }
            //          catch (Exception Ex)
            //        {
            //          throw new System.ArgumentException("Some notes cannot be match with this tranposition, Error : " +Ex.ToString());
            //    }
        }