divorced-coders / divorce-analysis-frontend

MIT License
0 stars 0 forks source link

Parav's Review #5

Open paravsalaniwal opened 9 months ago

paravsalaniwal commented 9 months ago

Features

  1. Ascending Bubble Sort Method

    • Using sorting to sort by each month's 'high' values
  2. Monthly Stocks Java

  3. Full frontend

Bubble Sort

Key Commit 1

Creating the sorting algorithm via bubble sort for the ascending order of the monthly stocks data to display that using the graphs.

package com.nighthawk.spring_portfolio.mvc.stocks.sorting;

import java.util.List;

import com.nighthawk.spring_portfolio.mvc.stocks.MonthlyStocks;

public class Ascending extends MonthlyStocksSorter {

  @Override
  public SortedData bubbleSort(List<MonthlyStocks> monthlyStocksList) {
    int n = monthlyStocksList.size();
    boolean swapped;

    super.sw.start();
    do {
        swapped = false;
        for (int i = 1; i < n; i++) {
            if (super.compareStrings(monthlyStocksList.get(i - 1).getHigh(), monthlyStocksList.get(i).getHigh()) > 0) {
                // Swap elements
                MonthlyStocks temp = monthlyStocksList.get(i - 1);
                monthlyStocksList.set(i - 1, monthlyStocksList.get(i));
                monthlyStocksList.set(i, temp);
                swapped = true;
            }
        }
        n--;
    } while (swapped);
    super.sw.stop();

    return new SortedData(super.comparisons, super.sw.getTotalTimeMillis(), monthlyStocksList);
  }

}

Monthly Stocks Java

Key Commit 1

Creating the Jpa Repository for the monthly stocks to create endpoints for the backend data to implement in the frontend fetching.

    @Autowired
    private MonthlyStocksJpaRepository repository;

    @GetMapping("/chronological")
    public ResponseEntity<List<MonthlyStocks>> getMonthlyStocks() {
        return new ResponseEntity<>(repository.findAll(), HttpStatus.OK);
    }

    @GetMapping("/high-to-low")
    public ResponseEntity<SortedData> getHighToLowMonthlyStocks() {
        MonthlyStocksSorter descending = new Descending();

        return new ResponseEntity<>(descending.selectionSort(repository.findAll()), HttpStatus.OK);
    }

    @GetMapping("/low-to-high")
    public ResponseEntity<String> getLowToHighMonthlyStocks() {
        MonthlyStocksSorter ascending = new Ascending();

        ObjectMapper objectMapper = new ObjectMapper();

        try {
            // Convert SortedData to JSON
            String json = objectMapper.writeValueAsString(ascending.bubbleSort(repository.findAll()));
            return ResponseEntity.ok(json);
        } catch (JsonProcessingException e) {
            // Handle exception if serialization fails
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
        }

    }
}

Frontend

Key Commit 1 Key Commit 2

Doing full fetching of both endpoints of the stocks API that we have as well as displaying the graph.

    async function fetchMonthlyData(month) {
      const url = `http://localhost:8098/api/DailyStocks/${month}`;

      try {
        // Fetch stock data from the backend
        const response = await fetch(url);
        const monthlyData = await response.json();

        // Extract dates and adjusted closing prices from the API response
        const dates = monthlyData.map(entry => entry.date);
        const prices = monthlyData.map(entry => parseFloat(entry.high));

        // Generate the graph using the data
        generateGraph(dates, prices);
      } catch (error) {
        console.error(error);
      }
    }
    async function fetchData(orderType) {
      const stockSymbol = document.getElementById('stockInput').value;
      const url = `http://localhost:8098/api/monthly-stocks/${orderType}`;

      try {
        // Fetch stock data from the backend
        const response = await fetch(url);
        const result.monthlyStocks = await response.json();
        console.log(result)
        // Check if the result is an array
        if (Array.isArray(result)) {
          // Iterate over each month in the result and generate a graph
          for (const monthlyData of result) {
            if (Array.isArray(monthlyData.data)) {
              const dates = monthlyData.data.map(entry => entry.date);
              const prices = monthlyData.data.map(entry => parseFloat(entry.high));

              // Generate the graph using the data
              generateGraph(dates, prices);
            }
          }
        } else if (Array.isArray(result.data)) {
          // Handle the case when the result is not an array (for chronological, ascending, and descending)
          const dates = result.data.map(entry => entry.date);
          const prices = result.data.map(entry => parseFloat(entry.high));

          // Generate the graph using the data
          generateGraph(dates, prices);
        }
      } catch (error) {
        console.error(error);
      }
    }

Cors Fix

Key Commit 1

Fixing the CORS error.

Overall Summary and Reflection

I felt like I had a big contribution towards getting this project complete and wanted to do this project because I was interested in stock analysis and how to incorporate Fibonacci into it, as well as sorting algorithms.

What did I learn

Commits

image image

Progress Issues

Errors faced Backend Progress Frontend Progress

Krishiv111 commented 9 months ago

Individual Review "Krishiv" grading "Parav"

Individuals Video, Issue(s), Commits(s)

Retrospective