Open Side Menu Go to the Top
Register
Programming homework and newbie help thread Programming homework and newbie help thread

04-14-2017 , 07:14 PM
Quote:
Originally Posted by goofyballer
Looking at what your code is doing, is the problem to...
- swap the 0th bit with the 31st
- swap the 1st bit with the 30th
- etc...
- down to swapping the 7th bit with the 24th?

So you're reversing and swapping the first and last bytes with each other?
Yes basically
Programming homework and newbie help thread Quote
04-14-2017 , 08:47 PM
Reversing a byte doesn't seem like a one-line operation; I'm willing to take StackOverflow links at their word. If it was something as simple as swapping the first and last bytes, that would be easy:

Code:
uint32_t swapFirstAndLastBytes(uint32_t input) {
  return (input & 0xffff00) | (input >> 24) | ((input & 0xff) << 24);
}
...but for the problem you stated, seems like maybe your teachers are claiming to know something SO doesn't.
Programming homework and newbie help thread Quote
04-15-2017 , 03:29 AM
Quote:
Originally Posted by MarkD
I'm not sure if this is the right thread or not, but it seems like it is close.

I don't have any work at the moment (which is bad) so I've decided to learn some python in the downtime. I also decided to do this in linux as I have no experience in linux as I actively avoided it in University. With that said I installed Linux Mint in a VM that I'm running in Windows 10, and then I installed Spyder and off I went going through some tutorials and getting my feet wet with some syntax. I'm not a noob and have experience with C#, C, C++, Visual Basic, etc., but not on a professional scale. I've programmed some small apps for work and personal projects.

So, I am going through Data Science from Scratch and I type up the following:
Code:
from matplotlib import pyplot as plt

years = [1950, 1960, 1970, 1980, 1990, 2000, 2010]
gdp = [300.2, 543.3, 1075.9, 2862.5, 5979.6, 10289.7, 14958.3]

#create a line chart, years on x-axis, gpd on y-axis
plt.plot(years, gdp, color='green', marker = 'o', linestyle = 'solid')

#add a title
plt.title("Nominal GDP")

#add a label to the y-axis
plt.ylabel("Billions of $")
plt.show()
And when I run it inside of the Spyder IDE I get this error:
Code:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
    execfile(filename, namespace)
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile
    builtins.execfile(filename, *where)
  File "/home/mdodd/markstuff/DataScience From Scratch/chapter3_1.py", line 9, in <module>
    from matplotlib import pyplot as plt
ImportError: No module named matplotlib
The first thing I did was decided that matplotlib didn't exist so I remembered that the book recommended I install anaconda, so I did that, and I tested it, and it is installed. I then ran the code in Spyder again and got the same error. I messed around with some stuff and then I went to the terminal and ran the code from the terminal with:
Code:
python chapter3_1.py
And it worked as expected. So now I know I have the libraries installed correctly and that the code is correct and it's something that is wrong with the Spyder IDE, but I have no idea what and I have done a lot of googling around on it. I suspect it's something to do with my PYTHONPATH but I really don't understand how to fix it.
Okay, I'll try and help, but I never used Spyder.

1- what OS are you on. Did you install Spyder with [apt-get | dnf | pacman | etc[
2- did you use pip?
3- Are you meaning to use Python 2 or are you trying to use Python 3?
4- What does your OS default to?

irt to #2: I've been burned many times using the OS package manager. Always always use pip or pip3. If you used the package manager, uninstall and use pip.

irt #3: Your OS may be defaulting to one version of Python while you are meaning to use another version. Are you sure you mean to use Python2 all the way?

And also, did you see this?

https://pythonhosted.org/spyder/inst...lling-on-linux

Don't get too scared of all the deps. They should be installed with pip.
Programming homework and newbie help thread Quote
04-15-2017 , 11:12 PM
Quote:
Originally Posted by goofyballer
Reversing a byte doesn't seem like a one-line operation
All operations are one-line if you have a long enough line -- Abraham Lincoln
Programming homework and newbie help thread Quote
04-16-2017 , 01:20 AM
Quote:
Originally Posted by well named
All operations are one-line if you have a long enough line -- Abraham Lincoln
That well named's name? Albert Einstein.
Programming homework and newbie help thread Quote
04-26-2017 , 01:00 AM
Quote:
Originally Posted by RustyBrooks
IBM/Intel assembly or other?
To answer this question, I'm pretty sure I'm looking for IA32
Programming homework and newbie help thread Quote
04-29-2017 , 08:44 AM
I hope this is the right thread etc, (within its remit).

Basically, this is my opportunity.

Betfair are releasing 2 yrs worth of historical data, per sport, in JSON format.

I specialise in cricket, and want to download all this data, into a query based program, so, I can run test queries/look for good future entry points, in games.

I use laptops/mobiles etc, but, have no coding knowledge.

Do I need to recruit a specialist for this ? If so, where would you look/what would u expect to pay ?

If I can do it myself, what is the best 'free' query program to use ?

Thx for any help.
Programming homework and newbie help thread Quote
04-29-2017 , 11:37 AM
I would be surprised if there is a ready made tool that will do this for you.

You might be able to teach yourself enough to do it, I'm not really sure exactly what would be needed, so it's a little hard to say.

If you know all the math you need to do and can explain it well enough, then I think most decent programmers could probably help you out. If not, I guess you'll need the help of someone who understands probability, sports betting, and maybe some aspects of machine learning or data analysis.
Programming homework and newbie help thread Quote
04-29-2017 , 12:07 PM
Do you want to learn coding? if so, this is the perfect opportunity given you have a relatively large task that is of interest to you needing to be done. "Necessity is the mother of invention", after all.

I'd guess "the best free query program" is PostgreSQL or R, maybe both. Or not. Maybe need a general purpose programming language too, such as Python or many many alternatives.

I expect a fairly high level of cricket sports betting knowledge is gonna be very useful here which I certainly do not have, so it's hard to say.
Programming homework and newbie help thread Quote
04-29-2017 , 12:30 PM
Where can you get this data?

Verstuurd vanaf mijn SM-G920F met Tapatalk
Programming homework and newbie help thread Quote
04-29-2017 , 05:46 PM
Sample files of the data have been released, but, the full site will be available from May 5.

Its not cheap .. £75 per mth, for 1 sec interval data, £150 for tick by tick / for each sport.

I have been asked not to reveal web address .. will update when its live.

//

I am 'too old' to learn to code .. 58 .. and am thinking of recruting a university teacher or student.

Would u look in the computer dept, or accounting/maths ?

Thx for all the replies.
Programming homework and newbie help thread Quote
04-29-2017 , 11:30 PM
If they release it in a reasonable, downloadable JSON format, the work required to import it into a database is pretty trivial, a day's work, maybe two. I would not recommend getting an undergrad to do it as you are liable to end up with a poorly designed database, but a decent postgrad or a lecturer should be able to do it no problem.

The problem I forsee is what happens then. It's probably a large amount of data, too much for something like Excel to handle. Are you planning to learn to write SQL queries? Personally I think SQL is one of the easiest programming-related things to learn if you understand how set-based operations work, but if you've never coded at all the learning curve might be steep. I forget the name of that cognitive bias where people underestimate how difficult it to learn a skill they themselves already possess, but whatever it's called, programmers have it in spades.
Programming homework and newbie help thread Quote
04-30-2017 , 01:18 AM
The data will have these fields :

Package
Data
Frequency
Data Fields
Depth
Pricing range per file (sport per month)
BASIC
Traded price updates by selection by frequency and market definition changes
1 minute intervals
EX_LTP, EX_MARKET_DEF
NA
Free
ADVANCED
All changes as per API stream format rolled up by frequency
1 second intervals
EX_BEST_OFFERS, EX_TRADED_VOL, EX_TRADED, EX_LTP, EX_MARKET_DEF,
3 levels
£50-£99
PRO
All changes as per API stream format
Tick by tick
EX_BEST_OFFERS, EX_ALL_OFFERS, EX_TRADED_VOL, EX_TRADED, EX_LTP, EX_MARKET_DEF, SP_TRADED, SP_PROJECTED
All
£120-£200


So, the number of data fields is fairly limited. Some work will be needed, to add length of game (20 overs/50 overs/5 day), and maybe further work, for which actual players were in each team.

I used to work at IBM (blush), maybe 25 yrs ago, and did some courses on SQL. That does seem a different life now .. and I had no idea if it was still relevent.

The JSON format makes it hard to immediately import into excel. I have found JSON to CSV converters etc .. but, am not sure thats the best route.

Will try find a like minded soul, who can program. Am fairly happy to spend $1000 or so, getting this set-up.

Cheers
Programming homework and newbie help thread Quote
04-30-2017 , 01:29 AM
Sorry, there are more fields .. at least for other sports.

Here is the sample file, for horse racing .. (some of it .. have left out most of data)

{"op":"mcm","clk":"2697939316","pt":1485776549858, "mc":[{"id":"1.129412695","marketDefinition":{"bspMarket ":true,"turnInPlayEnabled":true,"persistenceEnable d":true,"marketBaseRate":5.0,"eventId":"28094274", "eventTypeId":"7","numberOfWinners":1,"bettingType ":"ODDS","marketType":"WIN","marketTime":"2017-01-31T17:50:00.000Z","suspendTime":"2017-01-31T17:50:00.000Z","bspReconciled":false,"complete" :true,"inPlay":false,"crossMatching":false,"runner sVoidable":false,"numberOfActiveRunners":12,"betDe lay":0,"status":"OPEN","runners":[{"adjustmentFactor":18.09,"status":"ACTIVE","sortP riority":1,"name":"Cliff","id":5152422},{"adjustme ntFactor":15.27,"status":"ACTIVE","sortPriority":2 ,"name":"Dark Confidant","id":9529149},{"adjustmentFactor":13.2, "status":"ACTIVE","sortPriority":3,"name":"Athleti c","id":6023516},{"adjustmentFactor":7.48,"status" :"ACTIVE","sortPriority":4,"name":"Rebel Lightning","id":10488674},{"adjustmentFactor":7.48 ,"status":"ACTIVE","sortPriority":5,"name":"Domini um","id":4486684},{"adjustmentFactor":7.48,"status ":"ACTIVE","sortPriority":6,"name":"Billyoakes","i d":8504164},{"adjustmentFactor":7.48,"status":"ACT IVE","sortPriority":7,"name":"Papou Tony","id":10145497},{"adjustmentFactor":6.43,"sta tus":"ACTIVE","sortPriority":8,"name":"Win Lose Draw","id":10738296},{"adjustmentFactor":4.99,"sta tus":"ACTIVE","sortPriority":9,"name":"Masamah","i d":3038744},{"adjustmentFactor":4.48,"status":"ACT IVE","sortPriority":10,"name":"Captain Bob","id":7413471},{"adjustmentFactor":4.05,"statu s":"ACTIVE","sortPriority":11,"name":"Smokethatthu nders","id":6801703},{"adjustmentFactor":3.54,"sta tus":"ACTIVE","sortPriority":12,"name":"Langham"," id":10629269}],"regulators":["MR_INT"],"venue":"Wolverhampton","countryCode":"GB","disco untAllowed":true,"timezone":"Europe/London","openDate":"2017-01-31T14:10:00.000Z","version":1545520208,"name":"7f Hcap","eventName":"Wolv 31st Jan"}}]}
{"op":"mcm","clk":"2698540716","pt":1485792946961, "mc":[{"id":"1.129412695","rc":[{"ltp":6.2,"id":10145497}]}]}
{"op":"mcm","clk":"2698627873","pt":1485795607488, "mc":[{"id":"1.129412695","rc":[{"ltp":4.7,"id":9529149}]}]}
{"op":"mcm","clk":"2698677660","pt":1485796847371, "mc":[{"id":"1.129412695","rc":[{"ltp":4.5,"id":6023516}]}]}


Each sport, will need a different database design - but, am only really interested with cricket.

Maybe I will throw some of my own man hrs at it .. but, really, its something I wuld like to farm out.
Programming homework and newbie help thread Quote
04-30-2017 , 06:55 AM
You could store all that JSON in a table with a JSON type column. PostgreSQL has a great JSON query system.

If you are using Python, you'd want to use psycopg2. You would just get your connector and basically do something like this:

Code:
def insert_json (j):
    conn.execute (
        """
        begin;

        insert into json_table (col)
        values ($$%s$$);

        commit;
        """, [j])
I don't recall the exact syntax, but the gist of the above is basically, the conn object gives some function, like execute to use. You need to wrap your insert commands in a transaction. The dollar signs are a special syntax in Postgres that allows you to insert single quotes without manually escaping them, which you definitely need when working with JSON.

After dumping everything into a single json-type column, you can use the json operators to extract the data and insert it into the table format you want.

I will tell you upfront that what I have above will not work. If you have problems with it later on, I can grab a working example, if you end up using this strategy.
Programming homework and newbie help thread Quote
05-04-2017 , 12:29 AM
let's say i have a program i'm debugging, and I got gdb to do a core dump. How in the name of sweet lucifer do I read/access this thing? I'm mostly looking for address information about what commands were passed via cli
Programming homework and newbie help thread Quote
05-04-2017 , 01:16 PM
nah, i already saw that. Ended up just manually doing the work and stumbling across the location I was looking for. Thanks though!
Programming homework and newbie help thread Quote
05-04-2017 , 06:23 PM
Quote:
Originally Posted by dundalk
I hope this is the right thread etc, (within its remit).

Basically, this is my opportunity.

Betfair are releasing 2 yrs worth of historical data, per sport, in JSON format.

I specialise in cricket, and want to download all this data, into a query based program, so, I can run test queries/look for good future entry points, in games.

I use laptops/mobiles etc, but, have no coding knowledge.

Do I need to recruit a specialist for this ? If so, where would you look/what would u expect to pay ?

If I can do it myself, what is the best 'free' query program to use ?

Thx for any help.
EDIT: sorry missed a whole page of replies (stupid tapatalk!) so the below is based on your OP and the one or two replies under it.

Really from Dundalk?

I'm a noob .NET developer, 1.5 years experience, so this is probably not the best way to go about it. Can't hurt to suggest it though

Using Visual Studio Community (free) I'd make a simple winform app (drag and drop UI elements) with a local database attached.
First functionality we'd need would be to parse the JSON data and then insert it to the database. Haven't checked but I'd be reasonably sure there are some pre built JSON to SQL libraries, I think there might even be some that allow you to query the JSON itself with LINQ in C#.

I'm not a SQL dev but once you've successfully parsed you're gonna need to think about the structure of your database. Something tells me one huge table isn't gonna help you.. So in order to query the data successfully it'll have to be split into a "relational db" ie you decide what data goes where and why. Also decide if you need to derive new data, why and where this is stored.
This could be done during the parsing or afterward in SQLserver.

For the actual quering part. You could do it all in SQLserver via T-SQL or you could add to the winform parser and make a simple UI reporting tab/tool. Simply put this would take criteria you select, convert it to a SQL statement (string) and send it through to the db.

Just a general overview of how I'd start to go about it. I'd be relatively sure my approach would change once I got more familiar with the task.

Pros: all free software, relatively simple functionality
Cons: you'd need to learn to use VS, SQLserver, at least the basics of C# (or VB) and how to write SQL statements (queries and CRUD)

Inb4 a senior dev craps all over the above lol. I'm just trying to help..

GL @dundalk

Last edited by DublinMeUp; 05-04-2017 at 06:27 PM. Reason: Didn't see newer posts
Programming homework and newbie help thread Quote
05-05-2017 , 04:41 AM
Thx .. people have been remarkably helpful.

I have done quite a few things .. and will update etc, if people find it helpful.

The data format, is 'bad' .. in that the initial opening price is quoted .. for example, 2.12, and then just the changes to that price, are recorded, every second, or tick by tick.

So, to find the exact price, 2 hrs in, you would need to take all the intervening changes, add them up, and add the opening price. Not the best.

So, I have a developer, building a replayer, which will help, and doing some other database work.

I have also contacted a university, which has a gambling research unit .. and asked for either a grad student, who wants to learn, or someone I can pay.

Once the data is stored properly, there are others, who want to help with the data mining.

So, things are coming along .. but, a trifle slowly, for now.
Programming homework and newbie help thread Quote
05-05-2017 , 08:43 AM
Quote:
Originally Posted by DublinMeUp
EDIT: sorry missed a whole page of replies (stupid tapatalk!) so the below is based on your OP and the one or two replies under it.

Really from Dundalk?

I'm a noob .NET developer, 1.5 years experience, so this is probably not the best way to go about it. Can't hurt to suggest it though

Using Visual Studio Community (free) I'd make a simple winform app (drag and drop UI elements) with a local database attached.
First functionality we'd need would be to parse the JSON data and then insert it to the database. Haven't checked but I'd be reasonably sure there are some pre built JSON to SQL libraries, I think there might even be some that allow you to query the JSON itself with LINQ in C#.

I'm not a SQL dev but once you've successfully parsed you're gonna need to think about the structure of your database. Something tells me one huge table isn't gonna help you.. So in order to query the data successfully it'll have to be split into a "relational db" ie you decide what data goes where and why. Also decide if you need to derive new data, why and where this is stored.
This could be done during the parsing or afterward in SQLserver.

For the actual quering part. You could do it all in SQLserver via T-SQL or you could add to the winform parser and make a simple UI reporting tab/tool. Simply put this would take criteria you select, convert it to a SQL statement (string) and send it through to the db.

Just a general overview of how I'd start to go about it. I'd be relatively sure my approach would change once I got more familiar with the task.

Pros: all free software, relatively simple functionality
Cons: you'd need to learn to use VS, SQLserver, at least the basics of C# (or VB) and how to write SQL statements (queries and CRUD)

Inb4 a senior dev craps all over the above lol. I'm just trying to help..

GL @dundalk
Not a SR dev, but I'll crap all over ti.

The strategy is, IMO, upside-down. The layers that matter are the data query (to the end-suer) and the retrieval / insertion (to the back-end).

For retrieval, you'd want a cron job that queries the data.

The next step is a staging. This staging could be insertion into a data table that is single-column JSON.

The next step is parsing / separation of the data. This is converting into relational format. The controversial part of this is deciding if you want to use triggers / SQL procedural languages or if you want to use VBA / C# / whatever else, to query and parse the data. Personally, I prefer using after-insert triggers and procedures, but that's a matter of taste.

An alternative plan is query the JSON, save the JSON to a .json file in the system, then use the backend code for I/O and data insertion.

Basically, the disagreement is where the abstraction layers are. I see the retrieval and parsing as an abstract code-only area, and the final query / data presentation as a UI part.

I've done this before. It isn't exactly difficult, but very time-consuming to make correct and fast.

And also, SQL Server is only free up to a certain point.
Programming homework and newbie help thread Quote
05-05-2017 , 12:17 PM
lol, knew that was coming.

I agree with you on some points, I'm just obviously bad and writing out my thought process.
Programming homework and newbie help thread Quote
05-06-2017 , 05:24 PM
http://stackoverflow.com/questions/7...g-an-interview

Quote:
Given an integer i and set X of k points x1, x2, ... xk on real line, select i points from set X so as to minimize the sum of the distance from every point in X to a point in i using Dynamic programming.
I don't get how this is a dynamic programming problem? The guy who replied and gave a long reply didn't show any relation to subproblems. It looks like his solution is to just iterate through the points, find the distance, and then keep the points with the lowest distance for the result set.
Programming homework and newbie help thread Quote
05-07-2017 , 11:46 AM
I've read that question a dozen times and I have no idea what is trying to be asked.

IRT to making it dynamic, you can make any problem dynamic. For a really stupid example:

"Sum the digits of a string"

Code:
# silly psedocode that's totally not correct:

my_string = "1010101110110"

for i in (my_string, take_at_a_time = 2):
     memo(i, i[0] + i[1])
I guess it should be memoizing the string up to i, but I'm sort of lazy to do it that way for the moment. I'm just saying that just because you can doesn't mean you should.
Programming homework and newbie help thread Quote
05-07-2017 , 09:00 PM
Quote:
Originally Posted by daveT
I've read that question a dozen times and I have no idea what is trying to be asked.

IRT to making it dynamic, you can make any problem dynamic. For a really stupid example:

"Sum the digits of a string"

Code:
# silly psedocode that's totally not correct:

my_string = "1010101110110"

for i in (my_string, take_at_a_time = 2):
     memo(i, i[0] + i[1])
I guess it should be memoizing the string up to i, but I'm sort of lazy to do it that way for the moment. I'm just saying that just because you can doesn't mean you should.
I originally thought I knew what the question was asking but reading it over and over again I agree there is some ambiguity in what they're asking.

Even the answer at stack exchange seemed confusing to me.

Sent from my SM-G900R4 using Tapatalk
Programming homework and newbie help thread Quote

      
m