Jump to content

Best Way to program a chart.

AustinB

I was wondering what the best way would be to program this chart: http://4.bp.blogspot.com/-gpZek44uRJU/UkRUeMOgSzI/AAAAAAAABwg/7DQ5Ql8Efcg/s1600/blackjack-chart.gif

 

I was thinking a bunch of if statements which would be too slow, inefficient and time consuming. 

Maybe some type of 2D Array?

 

Language: Python

Looking for a Programming Project take a look here!

http://linustechtips.com/main/topic/407332-looking-for-a-project-idea-start-here/

Link to comment
Share on other sites

Link to post
Share on other sites

I would just do a 2D array that stores enum values for fast comparisons and what not.

CPU: Intel i7 - 5820k @ 4.5GHz, Cooler: Corsair H80i, Motherboard: MSI X99S Gaming 7, RAM: Corsair Vengeance LPX 32GB DDR4 2666MHz CL16,

GPU: ASUS GTX 980 Strix, Case: Corsair 900D, PSU: Corsair AX860i 860W, Keyboard: Logitech G19, Mouse: Corsair M95, Storage: Intel 730 Series 480GB SSD, WD 1.5TB Black

Display: BenQ XL2730Z 2560x1440 144Hz

Link to comment
Share on other sites

Link to post
Share on other sites

A matrix would be your best bet.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Without a real understanding of the context I would at least start by thinking in terms of breaking down the concerns:

  1. We have some kind of grid with at least two axis: X & Y
  2. We have an entity that needs to be displayed in our grid
  3. Our entity will have a value

From these one can clearly deduce that there is at least:

  1. A Model - some data
  2. A View - somewhere to display the data

With that in mind we can implement the following class (pseudo code) for our model:

class Entity{   int XAxis   int YAxis   enum Value}

Our enum type will describe the possible values. Each instance of our class will hold information on where it goes on the X and Y as well as what it's current value will be: DD, S, H, P and so on... We can then store our class instances in a list - this will be our Model that we will keep separated and encapsulated from the rest of the application. The display of this data (our list of classes) is up to whatever layer of the application forms the View (UI) and consumes the Model.

 

There's no need for complicated arrays of arrays or dictionaries because that is breaking encapsulation and exposing implementation details... all big no noes...

 

Now you may be wondering how we are to cope with the non continuity of the axis values i.e. starting at '8' and running through strange ranges such as 'A,7' and so on, particularly in the case of the one on the left; and what we do about the grid itself for that matter...

 

It's still relatively straightforward if you consider these concepts in terms of meta information or rather as a particular view onto the underlying data. In other words, we have a Model that is completely dissociated in concept from the way in which we will display it. It has it's own concept of ordering and it's a simple one at that - just a range of integers from 0 to whatever... It doesn't care that it is to be displayed in a strange grid or whatever.

 

As I said, it's up to the View layer as to how exactly it wants to interpret the data. It's as simple as saying well I have a range of values but I want to map them to some other range of values for display purposes and they happen to be in a grid arrangement with an X and a Y axis - this is just a particular way of viewing the data.

 

You'd ideally accomplish this by inserting another layer in between where your View is consuming the Model and how it's displaying it. This layer would probably be some kind of interface that abstracts away the details of how the data is remapped or reshaped to a series of concrete implementations (as many as you require for the View) and possibly another that encapsulates the rendering process (depending on the complexity at this point).

 

This is where, if you want to do thing correctly you will need to understand and master a number of different design patterns such as Model View Controller (MVC), Model View View Model (MVVM), Strategy and Factory for example. You do have some choices open to you on the patterns but this is going to come down to theory work i.e. engineering and design principles. Go and do some research  :lol:

 

As a further note: if you are thinking that the Model class is coupled to the View in terms of what an axis means i.e. X and Y (being a particular view based concept) then it doesn't have to be. You could roll the axes themselves up into an interface... 'Position' or whatever thereby pushing out the implementation detail yet again. I chose a simple example but you don't have to stop there. Get the simplest and most concrete thing working first and then refactor later - this is the Agile way.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

Use a 2-dimensional Python list, like so:
 
 

myList = [    [ None, "2", "3", "4", ...],    [ 8, "H", "H", ...]]

(Note that the ellipses stand for the rest of the List elements, not actually part of the code. :P)
 
The trick is to sort it into lists that would represent a data that as akin to something that Excel might understand. This means that you should probably remove the table headings from the List data itself, and instead use those as descriptors for your graph.
 
If you're building a chart, I'd recommend MatPlotLib or Plotly.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×