I hope this question makes sense, I have been literally trying to figure this out for two complete days.
I am trying to create a very small script, which I can then convert into a Flask web app, for comparing SPECint processor scores.
A bit of background:
From specint.org, I can download csv files containing benchmark information about processors and servers they have benchmarked. The idea of my app is to do the following:
Ask users for the benchmark they need (cint or rint), the server model, and the processor they're interested in. This must be done twice, for server 1 and server 2 so I can compare them.
I need to check that the information they are entering is correct, i.e. if someone enters as processor name XYZ it should raise an error and prompt for entering a valid query. For this, I'm planning to dump a version of the whole database into my own database, so I can perform the check before actually downloading the csv file from the server.
If the information entered is valid, I would dynamically generate the correct url for downloading and reading the csv file containing the benchmark score information, directly from SPECint's server.
Once I have downloaded and processed the information for both servers, I would apply some simple math and return the results saying something like this: "Server 1 is 10% faster/slower than server 2", or something like that.
As you probably imagine, this will require a lot of duplicated code, so it seems it's the perfect use-case for a class. I have been performing some tests, and the results are promising.
However, my issue is that I have not been able to figure out how to capture the user inputs, test the inputs, download the corresponding csv file, and pass the user inputs all on a per-instance fashion, without having to duplicate code somewhere. I have been searching and searching, and it seems a @classmethod
is what I need, but I'm not sure since the use of it still seems quite esoteric to me (I'm a newbie) (ref: Example of Class with User Input)
For example, this is kinda working:
My class:
class Baseline:
def __init__(self, benchmark, model, processor):
self.benchmark = benchmark
self.model = model
self.processor = processor
Capturing and printing instance results.
old_server = inputs.Baseline(test=input("Select benchmark: "),
model=input("Enter model: "),
processor=input("Enter processor: ")
)
new_server = inputs.Baseline(test=input("Select benchmark: "),
model=input("Enter model: "),
processor=input("Enter processor: ")
)
print(old_server.benchmark)
print(old_server.model)
print(new_server.benchmark)
print(new_server.model)
As you can see, I'm already repeating code, and instead, I'd like to do everything from within the class, so I can simply call instances of it to both capture, test, download, and return the results. As I said earlier, it seems that @classmethod
is the answer, but I'd appreciate any guidance, hopefully with a bit of sample code so I can fully grasp the concepts.