Skip to content
This repository was archived by the owner on Oct 15, 2022. It is now read-only.

Guitar Chord Diagrams - #858

Merged
abeyang merged 18 commits into
duckduckgo:masterfrom
charles-l:master
Mar 2, 2015
Merged

abeyang merged 18 commits into
duckduckgo:masterfrom
charles-l:master

Conversation

@charles-l

Copy link
Copy Markdown
Contributor

What does your Instant Answer do?
It returns a requested guitar chord diagram.

What problem does your Instant Answer solve (Why is it better than organic links)?
Easier access.

What is the data source for your Instant Answer? (Provide a link if possible)
The GD::Tab::Guitar cpan module. (http://search.cpan.org/~taniguchi/GD-Tab-Guitar-0.03/lib/GD/Tab/Guitar.pm)

Why did you choose this data source?
Because it generates the diagrams.

Are there any other alternative (better) data sources?
Not that I know of.

What are some example queries that trigger this Instant Answer?
'G guitar chord' 'G#m6 guitar chord'

Which communities will this Instant Answer be especially useful for? (gamers, book lovers, etc)
Musicians.

Is this Instant Answer connected to a DuckDuckHack Instant Answer idea?
(https://duck.co/ideas/idea/537/piano-guitar-chords), but it looks like it was abandoned?

Which existing Instant Answers will this one supercede/overlap with?
None.

Are you having any problems? Do you need our help with anything?
Nope.

What does the Instant Answer look like? (Provide a screenshot for new or updated Instant Answers)
screen shot 2014-12-19 at 7 07 51 pm

[x] Added metadata and attribution information (https://duck.co/duckduckhack/metadata)
[x] Wrote test file and added to t/ directory (https://duck.co/duckduckhack/goodie_tests)
[x] Verified that instant answer adheres to design guidelines (https://duck.co/duckduckhack/design_styleguide)
[x] Verified that instant answer adheres to code styleguide (https://duck.co/duckduckhack/code_styleguide)
[x] Tested cross-browser compatibility

Please let us know which browsers/devices you've tested on:
- Windows 8
    [] Google Chrome
    [] Firefox
    [] Opera
    [] IE 10

- Windows 7
    [] Google Chrome
    [] Firefox
    [] Opera
    [] IE 8
    [] IE 9
    [] IE 10

- Windows XP
    [] IE 7
    [] IE 8

- Mac OSX
    [x] Google Chrome
    [x] Firefox
    [] Opera
    [x] Safari

- iOS (iPhone)
    [x] Safari Mobile
    [] Google Chrome
    [] Opera

- iOS (iPad)
    [] Safari Mobile
    [] Google Chrome
    [] Opera

- Android
    [] Firefox
    [] Native Browser
    [] Google Chrome
    [] Opera

@charles-l charles-l changed the title Chords show up for queries Guitar Chord Diagrams Dec 20, 2014
@mintsoft mintsoft self-assigned this Dec 20, 2014
Comment thread lib/DDG/Goodie/GuitarChords.pm Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this won't work in IE8

@mintsoft

Copy link
Copy Markdown
Collaborator

@charles-l thanks for the PR; looks cool & useful! I'm not sure what we're going to do about the IE8 dataURI compatibility problem;

@jagtalon @moollaza Any ideas on the best way to handle this? The only option I can think of is to actually save all the PNG's into the /share/ and <img src them in

@mintsoft

Copy link
Copy Markdown
Collaborator

@charles-l also there appears to be a dependecy issue: https://travis-ci.org/duckduckgo/zeroclickinfo-goodies/jobs/44633711#L275
Can you explicitly add GD into dist.ini; hopefully it'll either fix it, or expose what's going on

@charles-l

Copy link
Copy Markdown
Contributor Author

@mintsoft Ah, I didn't realize I could generate the images in the /share/ folder until after submitting the pull request. Generating the images on the fly takes more resources and doesn't make much sense since the chords will always be the same. If I pre-generate the images it will also fix support for IE8. I'll rewrite that part.

I did add GD::Tab::Guitar = 0.03 to dist.ini. However, it requires the libgd2-xpm-dev package to generate images. Is there some way of adding that?

I'll also look through the supported chords to see if my regex is blocking anything.

@mintsoft

Copy link
Copy Markdown
Collaborator

@charles-l No problem; it's not well documented functionality :)

Looking at the current packages, libgd2-xpm-dev is actually libgd-dev these days. WRT to actually handling system depedencies, I don't know what the current state of affairs is (we we're debating a similar issue here: #713)

@jagtalon / @moollaza what's the best/easiest way to add a system dependency in or should we look for another method?

@charles-l

Copy link
Copy Markdown
Contributor Author

@mintsoft Hmm... is there some trick to getting the path to a /share/ image? If I use share('imgname.png');, it grabs the absolute position (relative to the filesystem) and not relative to the server. The result is that the image is inaccessible from anywhere but the server (because the server is the only thing that can see it).

I was thinking this might help, but it also is embedding as base64...

@mintsoft

Copy link
Copy Markdown
Collaborator

@charles-l I thought there was a way of doing it which was handled by the ImageRole; however I didn't realise it was Data URI'ing it. I'll have to loop in @moollaza and @jagtalon as they might have a better idea than me.

@moollaza

Copy link
Copy Markdown
Member

@mintsoft @charles-l

As you see, share() won't work for us here because the asset paths for web requests need to be versioned, /share/spice/1234/image.png.

The ImageRole will be your best bet, I know it's used in the SunInfo Goodie. This approach base64 encodes the image.

Alternatively you could use the DDG.get_asset_path('goodie_name', 'asset_name') function, but that would require inline JS which is a bit ugly. Once Goodies have better templates that's probably the way things will go.

@charles-l

Copy link
Copy Markdown
Contributor Author

@moollaza is it OK to use Base64 even if it isn't supported by IE8? Right now, I'm leaning towards the inline JavaScript (even though it's kind of a hacky work around).

@mintsoft

Copy link
Copy Markdown
Collaborator

@charles-l I think use the ImageRole for now, we know it doesn't work with IE8 so we'll have to solve that within the Role. That's essentially already a problem (#770)

@moollaza seem reasonable?

@moollaza

Copy link
Copy Markdown
Member

@charles-l yup, I agree with @mintsoft -- it's a tolerated bug I hope to fix soon

@charles-l

Copy link
Copy Markdown
Contributor Author

OK, I switched over to ImageRole and updated regex. You can generate the images in share/ by cding to the directory and running make.

Comment thread lib/DDG/Goodie/GuitarChords.pm Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you know you can use named captures? It might make this a little simpler

/(?<m>$date_number)/
# then use it 
print $+{'m'}

@mintsoft

Copy link
Copy Markdown
Collaborator

@charles-l Cool, that's a nice way of doing the image creation!

The only thing that 'bothers' me now is that the regex + parsing section is a little difficult to follow, I think it could probably be done with more of a

$a = 'm' if ($a =~ /minor/);
$b = 'M' if ($b =~ /major/);
return "$a $b $c $d";

kind of thing, rather than appending onto the string as you go which might make it a bit clearer

@mintsoft

Copy link
Copy Markdown
Collaborator

@charles-l Also, before I hook in the design guys can you make it return the name of the chord I.e. G7sus4 in the output in addition to the image?

@charles-l

Copy link
Copy Markdown
Contributor Author

@mintsoft, it already displays the chord name in the label of the image. Do you want html text in addition?

@charles-l

Copy link
Copy Markdown
Contributor Author

@mintsoft that's my bad, the images are generated to the share directory, but the file names have ( and ) in them, so when dzil install finds them, they aren't escaped, and it fails.

@charles-l

Copy link
Copy Markdown
Contributor Author

@jagtalon @mintsoft I think everything should be working now :)

@charles-l

Copy link
Copy Markdown
Contributor Author

Huh. The second build failed for some reason...

Comment thread lib/DDG/Goodie/GuitarChords.pm Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mintsoft err... sorry, I'm still missing it. It's saying something about a TAP plan? Dunno what that is, though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@charles-l you need to scroll up a little to line 3675:

[23:52:22] t/GuitarChords.t ................. Smartmatch is experimental at /home/travis/build/duckduckgo/zeroclickinfo-goodies/.build/9vst6yMqvN/blib/lib/DDG/Goodie/GuitarChords.pm line 67.

Compilation failed in require at t/GuitarChords.t line 12.

[23:52:22] t/GuitarChords.t ................. Dubious, test returned 255 (wstat 65280, 0xff00)

No subtests run 

The problem is the "smartmatch" operator (~~), which I guess is considered experimental. Any chance you can find an alternative to that?

@mintsoft

Copy link
Copy Markdown
Collaborator

@charles-l I fixed the most recent build problem in master yesterday; can you merge-in again?

@charles-l

Copy link
Copy Markdown
Contributor Author

@mintsoft merged, and it works! :D

@mintsoft

Copy link
Copy Markdown
Collaborator

@charles-l Good news then! @jagtalon @moollaza I think this is ready

@moollaza

Copy link
Copy Markdown
Member

Sorry about the delay guys, will try and get around to this one soon!

@charles-l

Copy link
Copy Markdown
Contributor Author

@moollaza no problem, and thanks for the heads up :)

@moollaza moollaza mentioned this pull request Feb 26, 2015
@ghost

ghost commented Mar 2, 2015

Copy link
Copy Markdown

@charles-l thanks! Putting it up on a server.

@ghost

ghost commented Mar 2, 2015

Copy link
Copy Markdown

@abeyang up on https://ddh9.duckduckgo.com/?q=G%23m6+guitar+chord&ia=answer! @moollaza I don't know much about guitar chords--maybe you could spot check the IA to see if the info is correct?

@ghost

ghost commented Mar 2, 2015

Copy link
Copy Markdown

@charles-l thanks for fixing the filenames btw!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a brief comment before the function which explains what it does? It's a bit intimidating at first glance.

abeyang added a commit that referenced this pull request Mar 2, 2015
@abeyang
abeyang merged commit c0909f8 into duckduckgo:master Mar 2, 2015
@ghost

ghost commented Mar 2, 2015

Copy link
Copy Markdown

💥

@moollaza

moollaza commented Mar 2, 2015

Copy link
Copy Markdown
Member

@charles-l Thanks again for taking the time to contribute! We really appreciate it. Feel free to stick around and comment/help on other PR's & Issues or even submit more Instant Answers!

@charles-l

Copy link
Copy Markdown
Contributor Author

@jagtalon, @moollaza Awesome, that's great news! I added some extra comments to the code.

@moollaza Yeah, I do plan on writing more instant answers soon ;)

@mintsoft

mintsoft commented Mar 3, 2015

Copy link
Copy Markdown
Collaborator

Congrats @charles-l 🎉

@charles-l

Copy link
Copy Markdown
Contributor Author

@mintsoft thank you

And thank you for all the help :)

@mintsoft

mintsoft commented Mar 3, 2015

Copy link
Copy Markdown
Collaborator

Happy to help @charles-l !

@moollaza

Copy link
Copy Markdown
Member

@charles-l congrats! It's live: https://duckduckgo.com/?q=G+guitar+chord&ia=answer

Thanks again for taking the time to contribute! We really appreciate it. Feel free to stick around and comment/help on other PR's & Issues or even submit more Instant Answers!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants