File size: 2,028 Bytes
c8e0891
ba970f2
c8e0891
 
 
 
ba970f2
 
 
 
c8e0891
cf52350
 
c8e0891
 
a49b336
 
c8e0891
a49b336
 
ba970f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c8e0891
 
 
 
 
a49b336
c8e0891
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from fastapi import FastAPI, File, UploadFile
import csv
from typing import List

app = FastAPI()

# Dictionaries to store URLs, API counts, and associated names
url_counts = {}
api_counts = {}
url_names = {}
api_names = {}

@app.post("/upload/")
async def upload_csv(file: UploadFile):
    if file.content_type == "text/csv":
        content = await file.read()
        content = content.decode('utf-8').splitlines()
        total_records = 0

        csvreader = csv.reader(content)
        header = next(csvreader)  # Skip the header row
        for row in csvreader:
            url = row[3]  # Assuming the URL is in the 4th column (index 3)
            api = row[4]  # Assuming the API is in the 5th column (index 4)
            url_name = row[2]  # Assuming the name associated with URLs is in the 3rd column (index 2)
            api_name = row[6]  # Assuming the name associated with APIs is in the 7th column (index 6)
            total_records += 1

            # Count URLs and associated names
            if url in url_counts:
                url_counts[url] += 1
            else:
                url_counts[url] = 1
                url_names[url] = url_name

            # Count APIs and associated names
            if api in api_counts:
                api_counts[api] += 1
            else:
                api_counts[api] = 1
                api_names[api] = api_name

        # Find redundant URLs and APIs with counts greater than 1
        redundant_urls = [url for url, count in url_counts.items() if count > 1]
        redundant_apis = [api for api, count in api_counts.items() if count > 1]

        # Calculate the percentage of redundant URLs and APIs
        percentage_redundant_urls = (len(redundant_urls) / total_records) * 100 if total_records > 0 else 0

        return {
            "Total GET Records": total_records,
            "% of Redundant GET Requests": round(percentage_redundant_urls, 2)
        }
    else:
        return {"error": "Invalid file format. Please upload a CSV file."}