static void Main(string[] args) { // prepare the client for access apiClient = new Client("guest", "guest", WdsfEndpoint.Sandbox); // the participant ID used here is an example. // create a participant ID by using the "Register Participant" example. Console.WriteLine("Loading participant."); ParticipantCoupleDetail participant = apiClient.GetCoupleParticipant(1404026); participant.Rounds.Clear(); try { Console.WriteLine("Saving participant."); bool isSuccess = apiClient.UpdateCoupleParticipant(participant); Console.WriteLine("Done."); } catch (ApiException ex) { Console.WriteLine(ex.InnerException.Message); } Console.ReadKey(); }
private static Uri SaveParticipant(CompetitionDetail competition, CoupleDetail selectedCouple) { Uri newParticipantUri = null; do { // choose start number Console.Write("Enter start number: "); string startNumber = Console.ReadLine(); int startNumberValue; int.TryParse(startNumber, out startNumberValue); ParticipantCoupleDetail participant = new ParticipantCoupleDetail() { CompetitionId = competition.Id, CoupleId = selectedCouple.Id, StartNumber = startNumberValue }; try { newParticipantUri = apiClient.SaveCoupleParticipant(participant); } catch (ApiException ex) { Console.WriteLine(ex.InnerException.Message); continue; } } while (false); return(newParticipantUri); }
private static void ListCouples(Link participantsReference) { List <ParticipantCouple> participants = apiClient.Get <ListOfCoupleParticipant>(new Uri(participantsReference.HRef)); foreach (ParticipantCouple participant in participants) { ParticipantCoupleDetail couple = apiClient.Get <ParticipantCoupleDetail>(new Uri(participant.Links.First(l => l.Rel == ResourceRelation.Self).HRef)); Console.Write("{0} {1} {2}\n", couple.StartNumber, couple.Name, couple.Country); } }
public Uri SaveCoupleParticipant(ParticipantCoupleDetail participant) { if (participant == null) { throw new ArgumentNullException("participant"); } ClearLinks(participant); return(SaveResource <ParticipantCoupleDetail>(participant, "participant")); }
public bool UpdateCoupleParticipant(ParticipantCoupleDetail participant) { if (participant == null) { throw new ArgumentNullException("participant"); } ClearLinks(participant); return(UpdateResource <ParticipantCoupleDetail>(participant, string.Format("participant/{0}", participant.Id))); }
///<inheritdoc/> public bool UpdateCoupleParticipant(ParticipantCoupleDetail participant) { if (participant == null) { throw new ArgumentNullException(nameof(participant)); } ClearLinks(participant); return(UpdateResource(participant, "participant/" + participant.Id)); }
internal static void Fill(ParticipantCoupleDetail couple, string scoreType, int rounds, int maxRounds, IEnumerable <OfficialWrapper> officials) { if (string.IsNullOrEmpty(scoreType)) { return; } var adjudicators = officials.Where(o => o.official.Task == "Adjudicator"); var chairman = officials.FirstOrDefault(o => o.official.Task == "Chairman"); Random rand = new Random(); for (int roundIndex = 1; roundIndex <= rounds; roundIndex++) { Round round = new Round() { Name = roundIndex == maxRounds ? "F" : roundIndex.ToString() }; couple.Rounds.Add(round); for (int danceIndex = 0; danceIndex < 5; danceIndex++) { Dance dance = new Dance() { Name = danceNames[danceIndex] }; round.Dances.Add(dance); switch (scoreType) { case "Scating": { if (roundIndex == maxRounds) { foreach (var adj in adjudicators) { dance.Scores.Add(new FinalScore() { OfficialId = adj.official.Id, Rank = rand.Next(1, 6) }); } } else { foreach (var adj in adjudicators) { if (rand.Next(0, 100) > 50) { dance.Scores.Add(new MarkScore() { OfficialId = adj.official.Id }); } } } break; } case "OnScale 1": { break; } case "OnScale 2": { break; } case "OnScale 3": { if (roundIndex == maxRounds) { bool isGroupDance = rand.Next(0, 10) >= 5; dance.IsGroupDance = isGroupDance; if (isGroupDance) { foreach (var adj in adjudicators) { int scoreCount = 0; dance.Scores.Add(new OnScale3Score() { OfficialId = adj.official.Id, CP = rand.Next(0, 10) >= 5 && scoreCount++ == 0 ? rand.Next(5, 10) : 0, MM = rand.Next(0, 10) >= 5 && scoreCount++ == 0 ? rand.Next(5, 10) : 0, PS = rand.Next(0, 10) >= 5 && scoreCount++ == 0 ? rand.Next(5, 10) : 0, TQ = scoreCount == 0 ? rand.Next(5, 10) : 0 }); } } else { foreach (var adj in adjudicators) { int scoreCount = 0; dance.Scores.Add(new OnScale3Score() { OfficialId = adj.official.Id, CP = rand.Next(0, 10) >= 5 && scoreCount++ < 2 ? rand.Next(5, 10) : 0, MM = rand.Next(0, 10) >= 5 && scoreCount++ < 2 ? rand.Next(5, 10) : 0, PS = scoreCount++ < 2 ? rand.Next(5, 10) : 0, TQ = scoreCount < 2 ? rand.Next(5, 10) : 0 }); } } } else { foreach (var adj in adjudicators) { if (rand.Next(0, 100) > 50) { dance.Scores.Add(new MarkScore() { OfficialId = adj.official.Id }); } } } break; } } } } }
static void Main(string[] args) { // prepare the client for access apiClient = new Client("guest", "guest", WdsfEndpoint.Sandbox); Console.Write("Enter competition ID:"); int competitionId; if (!int.TryParse(Console.ReadLine(), out competitionId)) { Console.WriteLine("Not a valid competition ID"); Console.ReadKey(); return; } CompetitionDetail competition = apiClient.GetCompetition(competitionId); Console.WriteLine( "Registering for competition {0} {1} {2} in {3}-{4} on {5}", competition.CompetitionType, competition.AgeClass, competition.Discipline, competition.Location, competition.Country, competition.Date); Console.WriteLine("Starting registration."); competition.Status = "Registering"; if (!apiClient.UpdateCompetition(competition)) { Console.WriteLine(string.Format("Failed to start registration. {0}", apiClient.LastApiMessage)); Console.ReadKey(); return; } // we want to list only couples that are allowed to participate in this competition string allAllowedAgeGroups = GetAllowedAgeGroups(competition); // prepare the couple filter Dictionary <string, string> coupleFilter = new Dictionary <string, string>() { { FilterNames.Couple.NameOrMin, string.Empty }, { FilterNames.Couple.Division, competition.Division }, { FilterNames.Couple.AgeGroup, allAllowedAgeGroups } }; do { // ask for an athlete name and list all possible couples ListCouples(coupleFilter); // choose one couple id from the list CoupleDetail selectedCouple = ChooseCouple(); // and save the couple as a new participant Uri newParticipantUri = SaveParticipant(competition, selectedCouple); // get the newly created participant to display it ParticipantCoupleDetail participant = apiClient.Get <ParticipantCoupleDetail>(newParticipantUri); Console.WriteLine("Added couple '{0}' to competition with ID:{1}.", participant.Name, participant.Id); Console.Write("An more? [Y]es/[N]o :"); } while (Console.ReadKey().Key == ConsoleKey.Y); Console.WriteLine("Closing registration."); competition.Status = "RegistrationClosed"; if (!apiClient.UpdateCompetition(competition)) { Console.WriteLine(string.Format("Failed to close registration. {0}", apiClient.LastApiMessage)); Console.ReadKey(); return; } // show all registered participants of this competition ListAllParticipants(competition); Console.ReadKey(); }
static void Main(string[] args) { // prepare the client for access apiClient = new Client("guest", "guest", WdsfEndpoint.Sandbox); Console.Write("Enter competition ID:"); int competitionId; if (!int.TryParse(Console.ReadLine(), out competitionId)) { Console.WriteLine("Not a valid competition ID"); Console.ReadKey(); return; } CompetitionDetail competition = apiClient.GetCompetition(competitionId); Console.WriteLine( "Closing competition {0} {1} {2} in {3}-{4} on {5}", competition.CompetitionType, competition.AgeClass, competition.Discipline, competition.Location, competition.Country, competition.Date); competition.Status = "Closed"; try { if (!apiClient.UpdateCompetition(competition)) { Console.WriteLine(string.Format("Failed to close the competition. {0}", apiClient.LastApiMessage)); Console.ReadKey(); return; } // we have to get the competition again to retreive the WRL coefficient competition = apiClient.GetCompetition(competitionId); Console.WriteLine(string.Format("The competitions coefficient is: {0}", competition.Coefficient)); // find the URL that contains all participants Uri allParticipantsUri = competition.Links .Where(l => l.Rel.StartsWith(ResourceRelation.CompetitionParticipants)) .Select(l => new Uri(l.HRef)) .FirstOrDefault(); Console.WriteLine("Results:"); Console.WriteLine(string.Format("{0,3} {1,4} {2,6} {3,-40} {4}", "Rank", "#", "Points", "Name", "Country")); ListOfCoupleParticipant participants = apiClient.Get <ListOfCoupleParticipant>(allParticipantsUri); foreach (ParticipantCouple participant in participants) { ParticipantCoupleDetail p = apiClient.GetCoupleParticipant(participant.Id); Console.WriteLine(string.Format("{0,3}. {1,4} {2,6} {3,-40} {4}", p.Rank, p.StartNumber, p.Points, p.Name, p.Country)); } } catch (ApiException ex) { Console.WriteLine(ex.InnerException.Message); } Console.ReadKey(); }
static void Main(string[] args) { // prepare the client for access apiClient = new Client("guest", "guest", WdsfEndpoint.Sandbox); Console.Write("Enter competition ID:"); int competitionId; if (!int.TryParse(Console.ReadLine(), out competitionId)) { Console.WriteLine("Not a valid competition ID"); Console.ReadKey(); return; } CompetitionDetail competition = apiClient.GetCompetition(competitionId); Console.WriteLine("Loading officials."); List <Official> adjudicators = GetAllAdjudicators(competition); if (adjudicators.Count == 0) { Console.WriteLine("No officials found. Can not add results!"); Console.ReadKey(); return; } Console.WriteLine("Loading participants."); List <ParticipantCouple> participants = GetAllParticipants(competition); if (participants.Count == 0) { Console.WriteLine("No participants found. Can not add results!"); Console.ReadKey(); return; } // one couple did not show up so we set it to "Noshow" ParticipantCouple missingParticipant = participants.First(); Console.WriteLine(string.Format("Setting 'No-Show' for participant: {0}", missingParticipant.Couple)); ParticipantCoupleDetail missing = apiClient.GetCoupleParticipant(missingParticipant.Id); missing.Status = "Noshow"; try { Console.WriteLine("Saving participant."); if (!apiClient.UpdateCoupleParticipant(missing)) { Console.WriteLine(string.Format("Could not update participant: {0}", apiClient.LastApiMessage)); } } catch (ApiException ex) { Console.WriteLine(ex.InnerException.Message); Console.ReadKey(); return; } // we just simulate the ranking here. Your application would follow the scating rules to determine the ranking int rank = 1; foreach (ParticipantCouple participant in participants.Skip(1)) { Console.WriteLine(string.Format("Setting scores for participant: {0}", participant.Couple)); ParticipantCoupleDetail coupleParticipant = apiClient.GetCoupleParticipant(participant.Id); FillResults(coupleParticipant, adjudicators); coupleParticipant.Rank = rank.ToString(); try { Console.WriteLine("Saving participant."); if (!apiClient.UpdateCoupleParticipant(coupleParticipant)) { Console.WriteLine(string.Format("Could not update participant: {0}", apiClient.LastApiMessage)); } } catch (ApiException ex) { Console.WriteLine(ex.InnerException.Message); Console.ReadKey(); return; } rank++; } Console.WriteLine("Setting competition status to processing."); competition.Status = "Processing"; apiClient.UpdateCompetition(competition); Console.WriteLine("Done."); Console.ReadKey(); }
private static void FillResults(ParticipantCoupleDetail participant, List <Official> adjudicators) { Random random = new Random(); // as we have loeded the participant from the API it may contain results from previous rounds. // always upload the entire mark/score set! participant.Rounds.Clear(); string[] danceNames = new string[] { "SAMBA", "CHA CHA CHA", "RUMBA", "PASO DOBLE", "JIVE" }; // results for round 1 // couple has got a star, this means a mark from every adjudicator for every dance with IsSet = true Round round1 = new Round() { Name = "1" }; participant.Rounds.Add(round1); foreach (string danceName in danceNames) { Dance dance = new Dance() { Name = danceName }; round1.Dances.Add(dance); foreach (Official adjudicator in adjudicators) { MarkScore score = new MarkScore() { IsSet = true, OfficialId = adjudicator.Id }; dance.Scores.Add(score); } } // results for round 2 Round round2 = new Round() { Name = "2" }; participant.Rounds.Add(round2); foreach (string danceName in danceNames) { Dance dance = new Dance() { Name = danceName }; round2.Dances.Add(dance); foreach (Official adjudicator in adjudicators) { // we use a random number to decide if the couple got a mark or not // in real life this would be taken from the adjudicator's decision if (random.Next(0, 10) > 5) { continue; } MarkScore score = new MarkScore() { OfficialId = adjudicator.Id }; dance.Scores.Add(score); } } // results for final round Round roundF = new Round() { Name = "F" }; participant.Rounds.Add(roundF); foreach (string danceName in danceNames) { Dance dance = new Dance() { Name = danceName }; roundF.Dances.Add(dance); foreach (Official adjudicator in adjudicators) { // we use a random number to determine the rank in a final round // in real life this would be taken from the adjudicator's decision int rank = random.Next(1, 6); FinalScore score = new FinalScore() { Rank = rank, OfficialId = adjudicator.Id }; dance.Scores.Add(score); } } }