Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
QuarkJets
Sep 8, 2008

duck monster posted:

Because gently caress javascript. This is a project fueled by hate.

The best kind of project

You're doing God's work, son. Finish it

Adbot
ADBOT LOVES YOU

Murodese
Mar 6, 2007

Think you've got what it takes?
We're looking for fine Men & Women to help Protect the Australian Way of Life.

Become part of the Legend. Defence Jobs.
What's the best way to find a project to contribute to? I have a 3-4 month break while my thesis gets assessed and just rewrote a massive chunk of my own big personal project so I'm sick of it, but still want to code something.

QuarkJets
Sep 8, 2008

Murodese posted:

What's the best way to find a project to contribute to? I have a 3-4 month break while my thesis gets assessed and just rewrote a massive chunk of my own big personal project so I'm sick of it, but still want to code something.

What kind of stuff are you interested in? Just try and think of a package that you use that you think could be improved, or a need that you think could be met by creating a new package.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

QuarkJets posted:

What kind of stuff are you interested in? Just try and think of a package that you use that you think could be improved, or a need that you think could be met by creating a new package.

You don't even need to think it needs improved, because even if you don't think it needs improvement, I guarantee it does and theres probably an issue tracker with lots of bugs needing fixes.

BigRedDot
Mar 6, 2008

Murodese posted:

What's the best way to find a project to contribute to? I have a 3-4 month break while my thesis gets assessed and just rewrote a massive chunk of my own big personal project so I'm sick of it, but still want to code something.
If you are interested in data vis, feel free to send me a PM.

StashAugustine
Mar 24, 2013

Do not trust in hope- it will betray you! Only faith and hatred sustain.

Is this the right place to ask tkinter questions? I have a quick question about layout.



That's an extremely rough mockup of what my UI is supposed to look like (it's a simulation of an industrial process.) I'm thinking of using grid layout, but the bottom half of the UI would have seperate columns from the top half. Is there a way to set that up, where you have two separate layouts on a single app?

America Inc.
Nov 22, 2013

I plan to live forever, of course, but barring that I'd settle for a couple thousand years. Even 500 would be pretty nice.
I'm trying to install a package for a student project, but my Python3.5 shell does not recognize any commands of the form
code:
easy_install package
easy_install.exe does exist in my Scripts folder, and I have my Scripts folder in my PATH variable, but the Python3.5 shell still does not recognize easy_install.
I apologize if this is a stupid question.

Communist Pie
Mar 11, 2007

...Robot!

LookingGodIntheEye posted:

I'm trying to install a package for a student project, but my Python3.5 shell does not recognize any commands of the form
code:
easy_install package
easy_install.exe does exist in my Scripts folder, and I have my Scripts folder in my PATH variable, but the Python3.5 shell still does not recognize easy_install.
I apologize if this is a stupid question.

in a command prompt, go to the directory with python.exe and try:
python ./scripts/easy_install.exe
and then whatever options you need with that

FoiledAgain
May 6, 2007

StashAugustine posted:

Is this the right place to ask tkinter questions? I have a quick question about layout.



That's an extremely rough mockup of what my UI is supposed to look like (it's a simulation of an industrial process.) I'm thinking of using grid layout, but the bottom half of the UI would have seperate columns from the top half. Is there a way to set that up, where you have two separate layouts on a single app?

Can't you set this up as multiple Frames? Then you can .grid() the individual widgets in each Frame however you want.

StashAugustine
Mar 24, 2013

Do not trust in hope- it will betray you! Only faith and hatred sustain.

FoiledAgain posted:

Can't you set this up as multiple Frames? Then you can .grid() the individual widgets in each Frame however you want.

Yeah that worked. I haven't used tkinter in like two years so my knowledge is rusty.

e:nvm figured it out

StashAugustine fucked around with this message at 19:27 on Nov 29, 2015

vodkat
Jun 30, 2012



cannot legally be sold as vodka
So I have a little script to download pdfs but I think the way I'm currently doing it is really inefficient. If the file doesn't exist already it just downloads it normally, if it does exist it checks the size of the pdf and if its different it downloads it with another name. But from what I understand the way I've written it entails downloading the file twice, once to check its size and then again if its a different size. My main concern is that I am potentially downloading lots of files only for them to be the same size and therefore not saved. Is there a way for me to find out the size of the pdf file without opening the whole file (this information isn't listed on the page anywhere, so comparing that isn't an option).

Here is my sitty code:

code:
if not os.path.exists(pdfpath): 
		urllib.urlretrieve(url, pdfpath)
if os.path.exists(pdfpath): s = urllib.urlopen(url)
if not os.path.getsize(pdfpath)==int(s.info()['Content-Length']):
		print 'Getting new PDF'
		if os.path.exists(pdfpath): urllib.urlretrieve(url, pdfpath_new)

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Under Windows what's the most straightforward library to print something like a label from python?

Using whatever font and size (Courier 20), and then whatever paper size (4x6) for example.

accipter
Sep 12, 2003

Bob Morales posted:

Under Windows what's the most straightforward library to print something like a label from python?

Using whatever font and size (Courier 20), and then whatever paper size (4x6) for example.

Using make, I created a template of a LaTex file that I then created with Python to produce the final LaTex file that I finally created with LaTex. Alternatively, I have used matplotlib to do something similar, but joined them together with PdfPages.

If you are comfortable with matplotlib, that's probably your best bet.

pctD
Aug 25, 2009



Pillbug
Anyone have experience with fuzzywuzzy? https://github.com/seatgeek/fuzzywuzzy

I'd like to use the process.extract function but it's way slower than just iterating through the list with a for loop and running fuzz.ratio on each item. Am I doing something wrong here?

code:
>>> type(cards)
<type 'list'>
>>> len(cards)
15708
>>>
>>> def fuzzy_match():
...     for c in cards:
...             score = fuzz.ratio("aetherling", c)
...             if score >= 80:
...                     print(c)
...
>>>
>>> def fuzzy_match2():
...     matches = process.extract("aetherling", cards, limit=3)
...     print(matches)
...
>>>
>>> def fuzzy_match3():
...     matches = process.extractOne("aetherling", cards)
...     print(matches)
...
>>>
>>> timeit.timeit(fuzzy_match, number=10)
Ætherling
Ætherling
Ætherling
Ætherling
Ætherling
Ætherling
Ætherling
Ætherling
Ætherling
Ætherling
0.833341121673584
>>>
>>> timeit.timeit(fuzzy_match2, number=10)
[(u'\xc6therling', 89), (u'Entering', 78), (u'Thornling', 74)]
[(u'\xc6therling', 89), (u'Entering', 78), (u'Thornling', 74)]
[(u'\xc6therling', 89), (u'Entering', 78), (u'Thornling', 74)]
[(u'\xc6therling', 89), (u'Entering', 78), (u'Thornling', 74)]
[(u'\xc6therling', 89), (u'Entering', 78), (u'Thornling', 74)]
[(u'\xc6therling', 89), (u'Entering', 78), (u'Thornling', 74)]
[(u'\xc6therling', 89), (u'Entering', 78), (u'Thornling', 74)]
[(u'\xc6therling', 89), (u'Entering', 78), (u'Thornling', 74)]
[(u'\xc6therling', 89), (u'Entering', 78), (u'Thornling', 74)]
[(u'\xc6therling', 89), (u'Entering', 78), (u'Thornling', 74)]
15.102123975753784
>>>
>>> timeit.timeit(fuzzy_match3, number=10)
(u'\xc6therling', 89)
(u'\xc6therling', 89)
(u'\xc6therling', 89)
(u'\xc6therling', 89)
(u'\xc6therling', 89)
(u'\xc6therling', 89)
(u'\xc6therling', 89)
(u'\xc6therling', 89)
(u'\xc6therling', 89)
(u'\xc6therling', 89)
15.063509941101074
>>>

Hed
Mar 31, 2004

Fun Shoe

vodkat posted:

So I have a little script to download pdfs but I think the way I'm currently doing it is really inefficient. If the file doesn't exist already it just downloads it normally, if it does exist it checks the size of the pdf and if its different it downloads it with another name. But from what I understand the way I've written it entails downloading the file twice, once to check its size and then again if its a different size. My main concern is that I am potentially downloading lots of files only for them to be the same size and therefore not saved. Is there a way for me to find out the size of the pdf file without opening the whole file (this information isn't listed on the page anywhere, so comparing that isn't an option).

Here is my sitty code:

code:

if not os.path.exists(pdfpath): 
		urllib.urlretrieve(url, pdfpath)
if os.path.exists(pdfpath): s = urllib.urlopen(url)
if not os.path.getsize(pdfpath)==int(s.info()['Content-Length']):
		print 'Getting new PDF'
		if os.path.exists(pdfpath): urllib.urlretrieve(url, pdfpath_new)
Urlopen's info method should just get the head and compare so I think you're doing it right. You may want to stand up a simplehttpserver and point your grabber there to verify though

vodkat
Jun 30, 2012



cannot legally be sold as vodka

Hed posted:

Urlopen's info method should just get the head and compare so I think you're doing it right. You may want to stand up a simplehttpserver and point your grabber there to verify though

Thanks, thats good to know!

5436
Jul 11, 2003

by astral
I'm writing an app in python. One part is a simple android/ios portion. Another is a website portion and the third part is a python API to tie it together. I'm using flask right now (just started). Should I use django to make the website portion easier? The website will be like a queue of work, when they finish one item it should load the next.

Space Kablooey
May 6, 2009


If you are already using Flask for the API, why not go whole hog? Are you having any specific difficulties using Flask?

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Bob Morales posted:

Under Windows what's the most straightforward library to print something like a label from python?

Using whatever font and size (Courier 20), and then whatever paper size (4x6) for example.

Here's what I ended up doing:

code:
import win32api
import win32print
from fpdf import FPDF

label = FPDF(orientation='P', unit='pt', format=(144,25.2)) # 2" x 0.35"
label.set_margins(0,0) # we don't want margins
label.set_auto_page_break(0) # turn of page breaks so we don't waste labels

# [part number, quantity]
parts_list = [['12345678', 6], ['ABCDEFGH', 10], ['SOME-PART', 4], ['FOOBAR', 20], ['FUNBUN', 2]]

for p in parts_list:
	for i in range(0, p[1]): # print a label for each individual part
		label.add_page()
		label.set_font('Courier', 'B', 18)
		label.cell(144, 25, p[0], 0, 0, 'C')

label.output('TEMP_LABEL.pdf')

win32api.ShellExecute (0, "printto", 'TEMP_LABEL.PDF', '\\\\ps1\\FUCKING_PRINTER', ".", 0)
Results:

Dominoes
Sep 20, 2007

5436 posted:

I'm writing an app in python. One part is a simple android/ios portion. Another is a website portion and the third part is a python API to tie it together. I'm using flask right now (just started). Should I use django to make the website portion easier? The website will be like a queue of work, when they finish one item it should load the next.
It's hard to tell from that description alone. If you're going to use more than one of the following, consider switching to Django: database, admin page, user login, email.

5436
Jul 11, 2003

by astral

Dominoes posted:

It's hard to tell from that description alone. If you're going to use more than one of the following, consider switching to Django: database, admin page, user login, email.

Yea I will most likely use all. Facebook/Google login, light email, and most likely a mysql db.

HardDisk posted:

If you are already using Flask for the API, why not go whole hog? Are you having any specific difficulties using Flask?

I like Flask a lot. To give you a better idea, there are users and commenters. A user will upload an image (through a simple android/ios app) and the commenters (there are many of them) will leave a comment on that image. Once that image gets 10 comments (from 10 unique commenters) it returns the comments to the user. The whole commenting workflow will be a web app. They look at the image, leave a short text comment, submit it, move onto the next item.

Space Kablooey
May 6, 2009


I'm biased because I'm working with Flask for three years now, and I strongly prefer it over Django overall. Something about Django just doesn't click with me for some reason, because every time I start a Django project to try and learn it, it feels bloated right out of the gate.

Having said that, for you project in particular you might need a lot of tuning for how each user's queue should behave (what jobs should appear in each queue and so on), and that will probably imply in a lot of tuning of your models. And for that, you will probably need a decent administrative interface, and Flask-Admin isn't quite there yet in terms of flexibility IMO (It's either a fairly rigid set of basic CRUD views or it's a completely blank template for you to build upon). Apparently Django's admin is better, but I really can't say how and where.

Another sore spot for Flask vs Django is the social login, were Django's has to be better because every Flask extension that I worked with so far was kinda poo poo.

Having said all that, though, if you have the time and the inclination to do that, I would suggest building your front-end in both frameworks so you can then compare them much better that way. Your application logic shouldn't have anything to do with your web framework anyway.

If you have any Flask questions, though, feel free to ask.

5436
Jul 11, 2003

by astral
I don't think the work queues need too much tuning, I haven't thought the full solution for it but I assume there will be a queue of items and it'll serve up the next item to whichever commenter is on. The interface is simple, display image, text box to comment, next button to submit that comment and get the next image. I do need social login (google + facebook).

Is it possible to simply program the service portion in flask and use something else for the front end? Well I guess I know its possible but is it optimal to getting off the ground quickly? I'm not really a developer so I haven't made a web app before.

Space Kablooey
May 6, 2009


5436 posted:

Is it possible to simply program the service portion in flask and use something else for the front end? Well I guess I know its possible but is it optimal to getting off the ground quickly? I'm not really a developer so I haven't made a web app before.

I think you can, but I don't think there's any point to using something else than flask specifically for the front-end, since it already does have something to both render your templates in the server (Jinja2) and to serve the rendered template as a HTML page.

Dominoes
Sep 20, 2007

I wrote a recommendation engine on Python/Django that tries to recommend places to travel to. It uses other people's choices (simplified pearson correlation), and a tag system. Does it seem to give reasonable results? website. Might use this as an excuse to learn scikit learn.

5436 posted:

Yea I will most likely use all. Facebook/Google login, light email, and most likely a mysql db.
I've made a few quick projects in Django, and one in Flask. Django feels bloated at first, and has more boilerplate. It's easier to start a basic website with Flask; less code and fewer files. SQLAlchemy as a Flask ORM feels on par with Django's, but implementing migrations with it's messy. Making Flask admin/user login/security work together involves tweaking templates; updates to one of those packages, or a dependency, can cause others to break. Imports get messy. I think Flask admin's default site looks prettier than Django's, but is more difficult to configure.

Dominoes fucked around with this message at 15:02 on Dec 4, 2015

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

The thing with Django's bloat is that, functionally, it doesn't matter. You just don't use the parts you don't want.

However, there is the initial problem of grasping all the parts of it and how they work together. Once you've done that though, it's simple to do a very basic website or something very complex.

SurgicalOntologist
Jun 17, 2004

Is there a preferred python library for dealing with GPS coordinates? Specifically I'll be converting them to a coordinate system in meters. I'm looking to maintain accuracy for distances of < 1 meter, so I'm hesitant to roll my own given the possibility of floating-point issues. However Google is not helping. This seems like a common enough issue that there would be a library, no?

Dominoes
Sep 20, 2007

Thermopyle posted:

The thing with Django's bloat is that, functionally, it doesn't matter. You just don't use the parts you don't want.

However, there is the initial problem of grasping all the parts of it and how they work together. Once you've done that though, it's simple to do a very basic website or something very complex.
I agree; now that I'm familiar with it and know what each part does, it's easy. Learning it (especially without a knowledge of databases etc) was a pain.

SurgicalOntologist posted:

Is there a preferred python library for dealing with GPS coordinates? Specifically I'll be converting them to a coordinate system in meters. I'm looking to maintain accuracy for distances of < 1 meter, so I'm hesitant to roll my own given the possibility of floating-point issues. However Google is not helping. This seems like a common enough issue that there would be a library, no?
Could you be more specific? What coordinate system to and from? I interface with them in pairs degree-decimals (ie no minutes, seconds etc; NSEW is determined by sign), then run them through trig equations to calculate things like a new position from an old position and heading, the distances between two points etc. You can convert to minutes/seconds etc with modulus math.

Dominoes fucked around with this message at 21:24 on Dec 4, 2015

SurgicalOntologist
Jun 17, 2004

Dominoes posted:

Could you be more specific? What coordinate system to and from? I interface with them in pairs degree-decimals (ie no minutes, seconds etc; NSEW is determined by sign), then run them through trig equations to calculate things like a new position from an old position and heading, the distances between two points etc. You can convert to minutes/seconds etc with modulus math.

Degree-decimal to x,y in meters (with the origin specified by another degree-decimal pair). Easy enough to implement Haversine myself, just thought there might be something out there already.

BannedNewbie
Apr 22, 2003

HOW ARE YOU? -> YOSHI?
FINE, THANK YOU. -> YOSHI.

SurgicalOntologist posted:

Degree-decimal to x,y in meters (with the origin specified by another degree-decimal pair). Easy enough to implement Haversine myself, just thought there might be something out there already.

Scikit-learn can do Haversine, although I don't know if there's anything special in that implementation compared to doing it yourself.

Dominoes
Sep 20, 2007

SurgicalOntologist posted:

Degree-decimal to x,y in meters (with the origin specified by another degree-decimal pair). Easy enough to implement Haversine myself, just thought there might be something out there already.
This library can supposedly convert to and from MGRS (a meter-based grid system), but I can't get it to compile.

Alternatively, you could (possibly?) calculate the heading and dist from the origin to the point using haversine, then use basic trig to convert it to a flat grid system. The error will be small enough for small distances.

For finding distance and bearing:

Python code:
def ellipsoid_radius(f):
    # f is geodetic latitude, in degrees
    f = radians(f)
    a = 6378137.0  # m, per WGS84
    b = 6356752.31424518  # m, per WGS84

    return sqrt(((a**2 * cos(f))**2 + (b**2 * sin(f))**2) / ((a * cos(f))**2 + (b * sin(f))**2))


def find_brg(point0: (float, float), point1: (float, float)) -> float:
    """Find the bearing, in radians, between two points.  Inputs are in degrees."""
    lat0, lon0 = radians(point0[0]), radians(point0[1])
    lat1, lon1 = radians(point1[0]), radians(point1[1])
    d_lon = lon1 - lon0

    brg = atan2(sin(d_lon)*cos(lat1), cos(lat0)*sin(lat1) - sin(lat0)*cos(lat1)*cos(d_lon))
    return (brg + &#964;) % &#964;


def find_dist(point0: (float, float), point1: (float, float)) -> float:
    """Calculate the distance between two lat-lons, in m.  Inputs are in degrees."""
    lat0, lon0 = radians(point0[0]), radians(point0[1])
    lat1, lon1 = radians(point1[0]), radians(point1[1])
    r = ellipsoid_radius(lat0)

    dlon = lon1 - lon0
    dlat = lat1 - lat0

    a = (sin(dlat/2)) ** 2 + cos(lat0) * cos(lat1) * (sin(dlon/2)) ** 2
    c = 2 * atan2(sqrt(a), sqrt(1-a))
    return r * c
You could use something like this to find your result if its in the north - east quadrant. You could modify it to make it work for all four quadrants by using an if statement, subtracting multiples of τ/4 from the bearing, and modifying the signs accordingly. Or a smarter solution I haven't thought of that works for all quadrants.
Python code:
def convert(origin, point):
    brg = find_brg(origin, point)
    dist = find_dist(origin, point)

    x = dist * sin(brg)
    y = dist * cos(brg) 
    return x, y

Dominoes fucked around with this message at 13:08 on Dec 5, 2015

Cingulate
Oct 23, 2012

by Fluffdaddy

Dominoes posted:

I wrote a recommendation engine on Python/Django that tries to recommend places to travel to. It uses other people's choices (simplified pearson correlation), and a tag system. Does it seem to give reasonable results? website. Might use this as an excuse to learn scikit learn.
Scikit-learn is really intuitive and easy to learn. You'll be running Random Forests in like 15 minutes.

yippee cahier
Mar 28, 2005

Might be tons of overkill, but I used the GDAL python bindings (http://gdal.org/) in the past and it worked well.

Baby Babbeh
Aug 2, 2005

It's hard to soar with the eagles when you work with Turkeys!!



Dominoes posted:

I wrote a recommendation engine on Python/Django that tries to recommend places to travel to. It uses other people's choices (simplified pearson correlation), and a tag system. Does it seem to give reasonable results? website. Might use this as an excuse to learn scikit learn.


It didn't find Mexico City, but the recommendations seemed reasonable.

Gangsta Lean
Dec 3, 2001

Calm, relaxed...what could be more fulfilling?

SurgicalOntologist posted:

Is there a preferred python library for dealing with GPS coordinates? Specifically I'll be converting them to a coordinate system in meters.


I think pyproj is what you're asking for. It's for converting a point from one coordinate system to another, for example I use it for converting from EPSG:4326 (your standard lat/lon projection) to EPSG:3857 (Web Mercator, where the coordinates are in meters). If that's what you're asking for, this is the recommended library. If you're worried about accuracy issues, be sure you use the right projection info for your source and destination projections when you call the Proj() constructor.

sund posted:

Might be tons of overkill, but I used the GDAL python bindings (http://gdal.org/) in the past and it worked well.


This works, too, is a VERY useful library, and is also using Proj.4 behind the scenes to do reprojections, but if you don't need the other stuff it supplies, pyproj is going to be much easier to install.

Emacs Headroom
Aug 2, 2003
The only time I tried to do a coordinate transformation in Python, I gave up and just used ogr2ogr.

SurgicalOntologist
Jun 17, 2004

Cool, thanks for the tips everyone. I did end up implementing it myself, but I'll check those options out as well. I didn't realize until now that I was essentially doing a map projection. :doh:

Dominoes: what is ʶ? And why won't this work in other quadrants? Seems fine since you're using atan2

Loezi
Dec 18, 2012

Never buy the cheap stuff
This might be a bit too specific (or even closer to a linear algebra questions than to a python questions), but I'm doing a machine learning class and was wondering whether there's a way to do the below thing without the loop, using only vector/matrix operations:

Python code:
for num in range(10):
        sums[num] = np.sign(weights[num].dot(data.T)).sum(axis=0)
weights is a [10,10,784] np.array and data is a [30000, 784] np.array.

Nippashish
Nov 2, 2005

Let me see you dance!

Loezi posted:

This might be a bit too specific (or even closer to a linear algebra questions than to a python questions), but I'm doing a machine learning class and was wondering whether there's a way to do the below thing without the loop, using only vector/matrix operations:

Python code:
for num in range(10):
        sums[num] = np.sign(weights[num].dot(data.T)).sum(axis=0)
weights is a [10,10,784] np.array and data is a [30000, 784] np.array.

You can use einsum to do it like this:
code:
sums = np.sign(np.einsum('ijk,ak->ija', weights, data)).sum(axis=1)
einsum is really powerful, but it tends to be slower than the standard BLAS ops so ymmv for speed.

There's also this monsterosity:
code:
np.sign((weights[:,None,:,:] * data[None,:,None,:]).sum(axis=3)).sum(axis=2)
which creates an enormous intermediate result and you should not do this.

Adbot
ADBOT LOVES YOU

Dominoes
Sep 20, 2007

Cingulate posted:

Scikit-learn is really intuitive and easy to learn. You'll be running Random Forests in like 15 minutes.
How does it relate and overlap with Tensorflow?

Baby Babbeh posted:

It didn't find Mexico City, but the recommendations seemed reasonable.
Thanks; the DB had it as 'Mexico'.


SurgicalOntologist posted:

Dominoes: what is ʶ? And why won't this work in other quadrants? Seems fine since you're using atan2
That was τ, ie tau; 2π; apparently SA doesn't like unicode chars in code segments.

You're right; I just tested the script I posted; it works as-is for all quadrants.

Dominoes fucked around with this message at 12:10 on Dec 5, 2015

  • Locked thread