public async Task <IActionResult> NewRecord([FromBody] FitnessRecord newRecord) { if (await dataStore.WriteRecord(newRecord)) { return(Ok("new record successfully written")); } return(StatusCode(400)); }
public async Task <bool> WriteRecord(FitnessRecord record) { var client = _httpFactory.CreateClient("WRITER"); HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, "/api/fitness-data"); var requestJson = JsonConvert.SerializeObject(record); message.Content = new StringContent(requestJson, Encoding.UTF8, "application/json"); var response = await client.SendAsync(message); return(response.IsSuccessStatusCode); }
public int CompareTo(object obj) { if (obj == null) { return(1); // this is greater than obj } if (!(obj is FitnessRecord)) { throw new ArgumentException("Object is not a FitnessRecord!"); } FitnessRecord other = (FitnessRecord)obj; return(Fitness.CompareTo(other.Fitness)); }
public async Task <bool> WriteRecord(FitnessRecord newRecord) { var records = await GetAllRecords(); if (records.Where(x => x.title.ToUpper().Equals(newRecord.title.ToUpper())).Count() > 0) { return(false); } using (StreamWriter sw = File.AppendText(FILE_PATH)) { var recordStr = JsonConvert.SerializeObject(newRecord); await sw.WriteLineAsync(recordStr); } return(true); }
private void Start() { CarNetworks = new NeuralNetwork[PopulationSize]; CarPairs = new int[PopulationSize][]; FitnessRecords = new FitnessRecord[PopulationSize]; for (int i = 0; i < CarPairs.Length; i++) { CarPairs[i] = new int[2]; } for (int i = 0; i < FitnessRecords.Length; i++) { FitnessRecords[i] = new FitnessRecord(); } }
public async Task <bool> WriteRecord(FitnessRecord newRecord) { return(false); }