How can I use a Lua module in MediaWiki to display graphs - lua

I currently have a Lua module that does some manipulation on data it is passed then I would like it to display a graph on an article.
I am having trouble getting the graph displaying properly however I have tried a couple of approaches thus far:
Output in the form of {{Graph:Chart|variablesHere}} using the graph template as is recommended on the extension page, which works fine usually. The problem with this approach is that (I assume) because it comes from a module the text isn't actually processed by MediaWiki and therefore display plaintext.
Using require('Module:Graph') and and printing the output to the page, however it does not correctly make a graph either as it isn't properly formatted and I haven't been able to understand how to convert it like Template:Graph:Chart does
Just looking for any suggestions on where to go from here.

Use frame:preprocess(string_containing_templates) to expand a string that contains templates such as Template:Graph:Chart.
If you want to avoid preprocessing, you could call the chart function of Module:Graph, but it is complicated to get the same result as expanding Template:Graph:Chart because you have to translate the contents of Template:Chart:Graph to Lua. To generate the same content as frame:preprocess("{{Graph:Chart|width=100|height=100|x=1|y=1}}"), you would do:
frame:extensionTag("templatestyles", nil, { src = "Graph:Chart/styles.css" })
.. frame:extensionTag (
"graph",
require("Module:Graph").chart { args = { width = '100', height = '100', x = '1', y = '1' } }
)
Here frame must be a frame object. Not very pretty, and if any changes are made to the template, they won't be reflected in your module code. So it is probably best to just preprocess the template.

Related

How to use variables in LUA 5.1 Touchosc

I'm trying, to wrap my head around Touchosc and script based on LUA 5.1.
I have a number of labels, called song0, song1, song2, and so on. I'm trying to set different values in these, using
local text = 'Smoke On The Water'
for i = 1, 2 do
self.children.pager1.children.main.children.song[i].values.text = text
end
but that gives me an error.
:-) I do need help.
Finn
Since you haven't provided the actual error, it's difficult to say what the problem is, but if I have to venture a guess, then try replacing ...children.song[i].values... with ...children["song"..i].values.... Since there is no table song, you just need to generate dynamic field names.

How to append one Google Doc to another using APIv1

I'm writing a merging program. Instead of creating one document per input row, I want the merged (template with input values replaced) output from each input row added to a single document.
And the template is not just text. It's another Google doc with a standalone table.
I started with the mail merge example and it works fine but produces a separate doc for each input row. I've written a helper function that I call for each output doc, with "dest_doc" set to my summary doc.
Sadly, this does not work since the API seems only to permit unstyled text insertion, not contents-from-a-Doc.
It works fine when using 'hello world ' -- this is properly replicated in the output file. But when I replace it with body or body['contents'] it fails.
Is there any way of doing this? I'd balk at writing a contents-tree-to-UpdateRequest translator.
def append_contents(dest_doc, source_doc):
"""Copy the contents of the source doc to the end of the destination doc
"""
document = DOCS.documents().get(documentId=source_doc).execute()
body = document.get('body')
requests = [
{
'insertText': {
'endOfSegmentLocation': {
'segmentId': '',
},
'text': 'hello world '
}
},
]
DOCS.documents().batchUpdate(documentId=dest_doc, body={'requests': requests}).execute()
return
Thanks for your time.
Unfortunately you can't use the insertText request to append a complex object (as the Body of another Document) to your Document. This request only accepts text.
I'm afraid that the only solution here would be to parse the elements of your documents and create a request translator for each one of their types.
Even in Apps Script as you can see in this example, the merge is done element per element according to its type (Text, Table, Image, Paragraph, etc.).
However, if this feature is really important to you, you should definitely submit a feature request here

Access all fields in Zapier Code Step

Is it possible to access all the fields from a previous step as a collection like json rather than having to explicitly setting each one in the input data?
Hope the screenshot illustrates the idea:
https://www.screencast.com/t/TTSmUqz2auq
The idea is I have a step that lookup responses in a google form and I wish to parse the result to display all the Questions and Answer into an email.
Hope this is possible
Thanks
David here, from the Zapier Platform team. Unfortunately, what I believe you're describing right now isn't possible. Usually this works fine since users only map a few values. The worst case is when you want every value, which it sounds like you're facing. It would be cool to map all of them. I can pass that along to the team! In the meantime, you'll have to click everything you're going use in the code step.
If you really don't want to create a bunch of variables, but you could map them all into a single input and separate them with a separator like |, which (as long as it doesn't show up in the data), it's easy to split in the code step.
Hope that helps!
The simplest solution would be to create an additional field in the output object that is a JSON string of the output. In a Python code step, it would look like
import json
output = {'id': 123, 'hello': 'world'}
output['allfields'] = json.dumps(output)
or for returning a list
import json
output = [{'id': 123, 'hello': 'world'},{'id': 456, 'bye': 'world'}]
for x in output:
x['allfields'] = json.dumps(output[output.index(x)])
Now you have the individual value to use in steps as well as ALL the values to use in a code step (simply convert them from JSON). The same strategy holds for Javascript as well (I simply work in Python).
Zapier Result
Fields are accessible in an object called input_data by default. So a very simplistic way of grabbing a value (in Python) would be like:
my_variable = input_data['actual_field_name_from_previous_step']
This differs from explicitly naming the the field with Input Data (optional). Which as you know, is accessed like so:
my_variable = input['your_label_for_field_from_previous_step']
Here's the process description in Zapier docs.
Hope this helps.

I want to display graphs and compare them

Display the points at which they merge , I was not able to find any library .....
Displaying any form of charts in iOS can be done in 2 ways.
Using webView to load a html string with the javascript files imported into it.
Using stringByAppendingFormat you can change the data points and refresh the webview.
http://www.fusioncharts.com/blog/2012/02/create-charts-for-iphone-and-ipad-apps-using-fusioncharts-xt/
Using a library to display them Natively. Something like Charts by Daniel Iohen Gindi. It is a bit extensive so just use the line Charts in your case and ignore the others.
https://github.com/danielgindi/Charts
Using the 2nd method (native) will always perform better, but the simplicity of html5 charts make it very easy to implement
To obtain points when lines meet is basically saying when 2 data has the same value. So you can just add an if statement and print the value out or store it as a variable.

Is there a way to automatically grab all the elements on the page using Selenium?

When creating tests for .Net applications, I can use the White library to find all elements of a given type. I can then write these elements to an Xml file, so they can be referenced and used for GUI tests. This is much faster than manually recording each individual element's info, so I would like to do the same for web applications using Selenium. I haven't been able to find any info on this yet.
I would like to be able to search for every element of a given type and save its information (location/XPath, value, and label) so I can write it to a text file later.
Here is the ideal workflow I'm trying to get to:
navigate_to_page(http://loginscreen.com)
log_in
open_account
button_elements = grab_elements_of_type(button) # this will return an array of XPaths and Names/IDs/whatever - some way of identifying each grabbed element
That code can run once, and I can then re-run it should any elements get changed, added, or removed.
I can then have another custom function iterate through the array, saving the info in a format I can use later easily; in this case, a Ruby class containing a list of constants:
LOGIN_BUTTON = "//div[1]/loginbutton"
EXIT_BUTTON = "//div[2]/exitbutton"
I can then write tests that look like this:
log_in # this will use the info that was automatically grabbed beforehand
current_screen.should == "Profile page"
Right now, every time I want to interact with a new element, I have to manually go to the page, select it, open it with XPather, and copy the XPath to whatever file I want my code to look at. This takes up a lot of time that could otherwise be spent writing code.
Ultimately what you're looking for is extracting the information you've recorded in your test into a reusable component.
Record your tests in Firefox using the Selenium IDE plugin.
Export your recorded test into a .cs file (assuming .NET as you mentioned White, but Ruby export options are also available)
Extract the XPath / CSS Ids and encapsulate them into a reusable classes and use the PageObject pattern to represent each page.
Using the above technique, you only need to update your PageObject with updated locators instead of re-recording your tests.
Update:
You want to automate the record portion? Sounds awkward. Maybe you want to extract all the hyperlinks off a particular page and perform the same action on them?
You should use Selenium's object model to script against the DOM.
[Test]
public void GetAllHyperLinks()
{
IWebDriver driver = new FireFoxDriver();
driver.Navigate().GoToUrl("http://youwebsite");
ReadOnlyCollection<IWebElement> query
= driver.FindElements( By.XPath("//yourxpath") );
// iterate through collection and access whatever you want
// save it to a file, update a database, etc...
}
Update 2:
Ok, so I understand your concerns now. You're looking to get the locators out of a web page for future reference. The challenge is in constructing the locator!
There are going to be some challenges with constructing your locators, especially if there are more than one instance, but you should be able to get far enough using CSS based locators which Selenium supports.
For example, you could find all hyperlinks using an xpath "//a", and then use Selenium to construct a CSS locator. You may have to customize the locator to suit your needs, but an example locator might be using the css class and text value of the hyperlink.
//a[contains(#class,'adminLink')][.='Edit']
// selenium 2.0 syntax
[Test]
public void GetAllHyperLinks()
{
IWebDriver driver = new FireFoxDriver();
driver.Navigate().GoToUrl("http://youwebsite");
ReadOnlyCollection<IWebElement> query
= driver.FindElements( By.XPath("//a") );
foreach(IWebElement hyperLink in query)
{
string locatorFormat = "//a[contains(#class,'{0}')][.='{1}']";
string locator = String.Format(locatorFormat,
hyperlink.GetAttribute("class"),
hyperlink.Value);
// spit out the locator for reference.
}
}
You're still going to need to associate the Locator to your code file, but this should at least get you started by extracting the locators for future use.
Here's an example of crawling links using Selenium 1.0 http://devio.wordpress.com/2008/10/24/crawling-all-links-with-selenium-and-nunit/
Selenium runs on browser side, even if you can grab all the elements, there is no way to save it in a file. As I know , Selenium is not design for that kinds of work.
You need to get the entire source of the page? if so, try the GetHtmlSource method
http://release.seleniumhq.org/selenium-remote-control/0.9.0/doc/dotnet/html/Selenium.DefaultSelenium.GetHtmlSource.html

Resources