def setMoodScore(self, MoodScore): if (MoodScore >= 0 and MoodScore < len(mood_tools.getEmotions())): self.MoodScore = MoodScore self.save() return True else: return False
def setMood(self, mood_int): if not (isinstance(mood_int, type(2))): return False if mood_int >= 0 and mood_int < len(mood_tools.getEmotions()): self.mood = mood_int self.save() return True else: return False
def __init__(self, weights=None, biases=None): self._emotions = getEmotions() self.nclasses = len(self._emotions) # Weights if weights: if len(weights) != 208: raise ValueError("There must be 208 weights for the model") self.setWeights(weights) else: self.setWeights("static/base_weights.json", True) # biases if biases: if len(biases) != 21: raise ValueError("Number of biases must be 21") self.setBias(biases) else: self.setBias("static/base_biases.json", True) # network if len(self._network) == 0: for i in range(4): self._network.append([]) weightCounter = 0 biasCounter = 0 for i in range(11): self._network[0].append({ 'weights': np.arange(weightCounter, weightCounter + 11, 1) }) weightCounter += 11 self._network[0][i]['bias'] = i biasCounter += 1 for i in range(6): self._network[1].append({ 'weights': np.arange(weightCounter, weightCounter + 11, 1) }) weightCounter += 11 self._network[1][i]['bias'] = i biasCounter += 1 for i in range(3): self._network[2].append({ 'weights': np.arange(weightCounter, weightCounter + 6, 1) }) weightCounter += 6 self._network[2][i]['bias'] = i biasCounter += 1 self._network[3].append( {'weights': np.arange(weightCounter, weightCounter + 3, 1)}) self._network[3][0]['bias'] = biasCounter
def updateReminders(self, MoodScore): #mood_int can be either the predicted mood or actual mood to get reminder moods = mood_tools.getEmotions() try: mood_str = moods[MoodScore] allReminders = mood_tools.getReminders() newReminders = allReminders[mood_str] except: return False currentReminders = self.reminderList.split(';') nonRepeated = [] for i in newReminders: try: currentReminders.index(i) except: nonRepeated.append(i) currentReminders.extend(nonRepeated) self.reminderList = ";".join(currentReminders) self.save() return True
def test_getEmotions(self): emotions = getEmotions() model1 = MoodNeuralNetwork() emotions2 = model1.getEmotions() self.assertEqual(emotions, emotions2) self.assertTrue(model1.getEmotions())
def getMoodToday(self, MoodScore): try: mood = mood_tools.getEmotions()[MoodScore] return mood except: return False