sorting (1)

Frontend:

image

  • prompts user to search for stock by sectors image
  • redirects to page with stocks with options to buy

    Backend:

    image

  • gets user input
  • calls model to get sorted stocks image
  • model code to clean csv file sector data to numeric values
  • returns a list of tuple contain stock symbol and clean numeric value image
  • code for a variation of bucket sorting
  • appends a empty list for every unique sector to a list callled :initialbucket
  • iterations through list return for cleaning
    • access cleaned number for list element
    • appends element to specific list(bucket) in initialbucket based on cleaned number
    • returns initialbucket image
  • code that is called in api
  • cleans json response based on same format as csv
  • calls sorts function to get initialbucket
  • creates sortdata by calling bucket with corresponding cleaned number image
  • uses bubble sorting to sort stocks symbols alphabetically
  • inefficient, but small tuples list size therefore reasonable usage
  • outer loop:
    • n-1 loops because each pass through the list places the next largest unsorted element in its correct position.
    • The outer loop controls the number of passes
  • Inner loop:
    • handles actual comparison
    • compares two elements and swaps if necessary: compares ascii values of strings
    • range(0, n - i - 1): ensures that the loop does not run past the last unsorted element
  • swapped flag:
    • used to optimize sorting
    • stops the outer loop if no passes are made in a single pass image
  • sortdata sent to class sortdisplay and is itterated through
  • gets symbol by checking 0 index of element
  • searching db for stock to get info and appends to list called returnlist
  • each element of returnlist is read and appended to newlist
  • new list is sent to frontend