
import json
import boto3
import time
import decimal
from boto3.dynamodb.conditions import Key, Attr

def vote_handler(event, context):
    dynamodb = boto3.resource('dynamodb')
    table = dynamodb.Table('Samples')

    for record in event['Records']:
        print(record['dynamodb']['NewImage'])



import json
import boto3
import time
import decimal
from boto3.dynamodb.conditions import Key, Attr

def vote_handler(event, context):
    dynamodb = boto3.resource('dynamodb')
    table = dynamodb.Table('Samples')
    
    ratings = dict()

    for record in event['Records']:
        type = record['eventName']
        disposition = 0
        if type == "INSERT" or type == "MODIFY":
            disposition = int(record['dynamodb']['NewImage']['vote']['N'])
        if type == "MODIFY" or type == "REMOVE":
            disposition += -int(record['dynamodb']['OldImage']['vote']['N'])
        sample = record['dynamodb']['Keys']['sample']['B']
        ratings[sample] = ratings.get(sample, 0) + disposition




Determine rating dispositions noted by the data changes and store them in a dictionary with the sample identification as the key.
Determine rating dispositions noted by the data changes and store them in a dictionary with the sample identification as the key.

  
  import json
  import boto3
  import time
  import decimal
  from boto3.dynamodb.conditions import Key, Attr
  
  def vote_handler(event, context):
      dynamodb = boto3.resource('dynamodb')
      table = dynamodb.Table('Samples')
+     
+     ratings = dict()
  
      for record in event['Records']:
-         print(record['dynamodb']['NewImage'])
+         type = record['eventName']
+         disposition = 0
+         if type == "INSERT" or type == "MODIFY":
+             disposition = int(record['dynamodb']['NewImage']['vote']['N'])
+         if type == "MODIFY" or type == "REMOVE":
+             disposition += -int(record['dynamodb']['OldImage']['vote']['N'])
+         sample = record['dynamodb']['Keys']['sample']['B']
+         ratings[sample] = ratings.get(sample, 0) + disposition
  
  
+ 
+ 
Determine rating dispositions noted by the data changes and store them in a dictionary with the sample identification as the key.
## Code Before:

import json
import boto3
import time
import decimal
from boto3.dynamodb.conditions import Key, Attr

def vote_handler(event, context):
    dynamodb = boto3.resource('dynamodb')
    table = dynamodb.Table('Samples')

    for record in event['Records']:
        print(record['dynamodb']['NewImage'])


## Instruction:
Determine rating dispositions noted by the data changes and store them in a dictionary with the sample identification as the key.
## Code After:

import json
import boto3
import time
import decimal
from boto3.dynamodb.conditions import Key, Attr

def vote_handler(event, context):
    dynamodb = boto3.resource('dynamodb')
    table = dynamodb.Table('Samples')
    
    ratings = dict()

    for record in event['Records']:
        type = record['eventName']
        disposition = 0
        if type == "INSERT" or type == "MODIFY":
            disposition = int(record['dynamodb']['NewImage']['vote']['N'])
        if type == "MODIFY" or type == "REMOVE":
            disposition += -int(record['dynamodb']['OldImage']['vote']['N'])
        sample = record['dynamodb']['Keys']['sample']['B']
        ratings[sample] = ratings.get(sample, 0) + disposition



