def updateWritingTone(user, writingTone, maintainHistory):
    """
    updateWritingTone updates the user with the writing tones interpreted based
    on the specified thresholds
    @param: user a json object representing user information (tone) to be used
    in conversing with the Conversation Service
    @param: writingTone a json object containing the writing tones in the
    payload returned by the Tone Analyzer
    """
    currentWriting = []
    currentWritingObject = []

    # Process each writing tone and determine if it is high or low
    for tone in writingTone['tones']:
        if tone['score'] >= WRITING_HIGH_SCORE_THRESHOLD:
            currentWriting.append(tone['tone_name'].lower() + '_high')
            currentWritingObject.append({
                'tone_name': tone['tone_name'].lower(),
                'score': tone['score'],
                'interpretation': 'likely high'
            })
        elif tone['score'] <= WRITING_NO_SCORE_THRESHOLD:
            currentWritingObject.append({
                'tone_name': tone['tone_name'].lower(),
                'score': tone['score'],
                'interpretation': 'no evidence'
            })
        else:
            currentWritingObject.append({
                'tone_name': tone['tone_name'].lower(),
                'score': tone['score'],
                'interpretation': 'likely medium'
            })

    # update user writing tone
    user['tone']['writing']['current'] = currentWriting
    if maintainHistory:
        if 'history' not in user['tone']['writing']:
            user['tone']['writing']['history'] = []
    user['tone']['writing']['history'].append(currentWritingObject)
def updateWritingTone ( user , writingTone , maintainHistory ) : currentWriting = [ ] currentWritingObject = [ ] for tone in writingTone [ 'tones' ] : if tone [ 'score' ] >= WRITING_HIGH_SCORE_THRESHOLD : currentWriting . append ( tone [ 'tone_name' ] . lower ( ) + '_high' ) currentWritingObject . append ( { 'tone_name' : tone [ 'tone_name' ] . lower ( ) , 'score' : tone [ 'score' ] , 'interpretation' : 'likely high' } ) elif tone [ 'score' ] <= WRITING_NO_SCORE_THRESHOLD : currentWritingObject . append ( { 'tone_name' : tone [ 'tone_name' ] . lower ( ) , 'score' : tone [ 'score' ] , 'interpretation' : 'no evidence' } ) else : currentWritingObject . append ( { 'tone_name' : tone [ 'tone_name' ] . lower ( ) , 'score' : tone [ 'score' ] , 'interpretation' : 'likely medium' } ) user [ 'tone' ] [ 'writing' ] [ 'current' ] = currentWriting if maintainHistory : if 'history' not in user [ 'tone' ] [ 'writing' ] : user [ 'tone' ] [ 'writing' ] [ 'history' ] = [ ] user [ 'tone' ] [ 'writing' ] [ 'history' ] . append ( currentWritingObject )
updateWritingTone updates the user with the writing tones interpreted based
    on the specified thresholds
    @param: user a json object representing user information (tone) to be used
    in conversing with the Conversation Service
    @param: writingTone a json object containing the writing tones in the
    payload returned by the Tone Analyzer