HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Is this class too over the top?

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
thisthetoptooclassover

Problem

In response to my previous question, I've refactored my class quite a bit. I've truncated my class a bit, because I have several methods that are very similar, with the exception of the query for the database. The class itself is at the 930 line number.

So, a little background. I'm not only the sole programmer on this project, but also in the company. And this is the first time I've ever attempted anything like this (only out of school 3 years). The purpose of the program is to query a local database, and generate a daily report. I've broken it up into two projects: WPF, and Report class library (what you see below). I already knew I didn't want the UI project to actually do the calculations. So I broke it off into the class library. I also knew I didn't want to just query the whole database and store ALL it's data in memory. So, I have each calculation calling a query method. I had looked into stored procedures, but this is a SQLite database, and stored procedures aren't supported.

Now, with all that in mind, I'm not really sure how best to improve this any further. So here I am, asking you guys: Is this too over the top, or is it fine?

```
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Linq;
using MySql.Data.MySqlClient;
using NLog;

namespace DailyReport
{
public class Report
{
#region Global Variables

#region Enums

public enum TimePeriod
{
Daily, Total, None
}

#endregion Enums

private static readonly Logger Logger = LogManager.GetLogger("ReportLogger");
public string ConnectionStringFile { get; private set; }

#region Query Parameters

public string StartTime { get; set; }
public string EndTime { get; set; }
public string Date { get; set; }

#endregion Query Parameters

#endregion Global Variables

#region Constructors

public Report(string stringFileName, DateTime

Solution

It looks like some of the methods are simply calculating the max or average. You might be able to move these types of calculations into the queries by using the corresponding aggregate functions. For example:

SELECT MAX(pump_press) FROM myDatabase
SELECT AVG(torque) FROM myDatabase


I believe the Footage calculation could even be done using:

SELECT MAX(measured_dist) - MIN(measured_dist) FROM myDatabase


I would also discourage the use of variables with names like tempList.

Code Snippets

SELECT MAX(pump_press) FROM myDatabase
SELECT AVG(torque) FROM myDatabase
SELECT MAX(measured_dist) - MIN(measured_dist) FROM myDatabase

Context

StackExchange Code Review Q#25372, answer score: 3

Revisions (0)

No revisions yet.