Is it possible to run Plotly.Net offline with F#?
You can store "plotly-2.6.3.min.js" and "require.min.js" locally and replace paths to html/javascript and see graphs. But when using Geo Maps, how to handle with world_50m or world_110m.json as needed also to draw a map?
For example first "baseMapOnly" from here https://plotly.net/05_0_geo-vs-mapbox.html and world_110m.json downloaded and pointed to GeoJson:
open Plotly.NET
// world_110m.json stored locally
let geoJsondata =
IO.File.ReadAllText("world_110m.json")
|> JsonConvert.DeserializeObject
let baseMapOnly =
Chart.PointGeo(GeoJson = geoJsondata, locations = [])
|> Chart.withMarginSize(0,0,0,0)
....
baseMapOnly
|> Chart.show
Also "https://cdn.plot.ly" and "https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6" of generated html replaced to local paths of "plotly-2.6.3.min.js" and "require.min.js".
When I try to render a map plot, there is still a call to https://cdn.plot.y/world_110m.json even though paths changed to html file.
What is wrong? Is there some other place to add local path?
Related
I am trying to create several network analyses from Twitter. To get the data, I used the academictwitteR package and their get_all_tweets command.
get_all_tweets(
users = c("LegaSalvini"),
start_tweets = "2007-01-01T00:00:00Z",
end_tweets = "2022-07-01T00:00:00Z",
file = "tweets_lega",
data_path = "tweetslega/",
bind_tweets = FALSE
)
## Binding JSON files into data.frame objects
tweets_bind_lega <- bind_tweets(data_path = "tweetslega/")
##Tyding
tweets_bind_lega_tidy <- bind_tweets(data_path = "tweetslega/", output_format = "tidy")
With this, I can easily access the ids for the creation of a retweet and reply network. However, the tidy format does not provide a tidy column for the mentions, instead it deletes them.
However, they are in my untidy df tweets_bind_lega , but stored as a list tweets_bind_afd$entities$mentions. Now I would like to somehow unnest this list and create a tidy df with a column that has contains the mentioned Twitter user ids.
Has anyone created a mention network with academictwitteR before and can help me out?
Thanks!
local maps = find.File("maps/*.bsp", "GAME")
map = (maps[math.random( #maps )])
print("Map randomized to " .. map )
This code above works on "ULX" on Garry's Mod, it uses find.File to read the directory of garrysmod/maps and return (in TABLE) all of the files in it ending with .bsp (all of the maps), however I do not wan't it to include maps that begin with certain parts, like "arena_" and "gm_", is there a way I can go about removing them and/or making it keep checking until It gets a map not beginning with that.
Any way I could do this? and preferable pure Lua please.
Oh and the site I'm using to test it is MOAIFiddle
It looks like the function you meant is file.Find instead of find.File.
http://wiki.garrysmod.com/page/file/Find
The following should work in Garry's Mod.
local maps = {}
local ignoredPrefixes = {"gm_","arena_"}
for _,map in ipairs(find.File("maps/*.bsp", "GAME"))do
local hasPrefix=false
for _,prefix in ipairs(ignoredPrefixes)do
if string.Left(map,string.len(prefix)) == prefix then
hasPrefix=true
break
end
end
if not hasPrefix then
table.insert(maps,map)
end
end
local randomMap = table.Random(maps);
print("Map randomized to "..randomMap)
What it does is read all maps in maps/ and then add all maps that do not have a certain prefix, defined in ignoredPrefixes, to the maps table.
When it is done doing so, a random map will be selected from the table.
I am looking to write a small firefox add-on that detects when files that were downloaded are (or have been) deleted locally and removes the corresponding entry in the firefox download list.
Can anybody point me to the relevant api to manipulate the download list? I cannot seem to find it.
The relevant API is PlacesUtils which abstracts the complexity of the Places database.
If your code runs in the context of a chrome window then you get a PlacesUtils glabal variable for free. Otherwise (bootstrapped, Add-on SDK, whatever) you have to import PlacesUtils.jsm.
Cu.import("resource://gre/modules/PlacesUtils.jsm");
As far as Places is concerned, downloaded files are nothing more than a special kind of visited pages, annotated accordingly. It's a matter of just one line of code to get an array of all downloaded files.
var results = PlacesUtils.annotations.getAnnotationsWithName("downloads/destinationFileURI");
Since we asked for the destinationFileURI annotation, each element of the resultarray holds the download location in the annotationValue property as a file: URI spec string.
With that you can check if the file actually exists
function getFileFromURIspec(fileurispec){
// if Services is not available in your context Cu.import("resource://gre/modules/Services.jsm");
var filehandler = Services.io.getProtocolHandler("file").QueryInterface(Ci.nsIFileProtocolHandler);
try{
return filehandler.getFileFromURLSpec(fileurispec);
}
catch(e){
return null;
}
}
getFileFromURIspec will return an instance of nsIFile, or null if the spec is invalid which shouldn't happen in this case but a sanity check never hurts. With that you can call the exists() method and if it returns false then the associated page entry in Places is eligible for removal. We can tell which is that page by its uri, which conveniently is also a property of each element of the results.
PlacesUtils.bhistory.removePage(result.uri);
To sum it up
var results = PlacesUtils.annotations.getAnnotationsWithName("downloads/destinationFileURI");
results.forEach(function(result){
var file = getFileFromURIspec(result.annotationValue);
if(!file){
// I don't know how you should treat this edge case
// ask the user, just log, remove, some combination?
}
else if(!file.exists()){
PlacesUtils.bhistory.removePage(result.uri);
}
});
I would like to open several pictures (.jpg) with F#.
All my pictures are stored in afile (filepath). I would like to show them to the user.
How can I do this using F#?
To open one picture, it tried something like :
open System.IO
let editPicture filepath =
let fileStream = File.Open(filepath,FileMode.Open)
fileStream.Visible <- True
but it doesn t work.
Here is a minimal quick and dirty WinForms F# snippet that shows a .jpg image on a screen:
open System
open System.Windows.Forms
open System.Drawing
let form = new Form()
let pb = new PictureBox()
pb.Image <- Image.FromFile(path-to-file-with-your-jpg-image)
pb.SizeMode <- PictureBoxSizeMode.AutoSize
form.Controls.Add(pb)
[<STAThread>]
do
Application.Run(form)
This may give you some initial traction and feel on what is involved into reaching your goal. But overall I agree with Carsten König that learning curve for doing UIs with F# is quite steep.
update: some background - i use the xml file to generate a set of pdfs (through a java application that drives JasperReports). all the reports are coming out blank when I use this new xml file. I've ruled out network problems because I use an old xml file from the same server that I run the java application with the new xml file. I've compared the two files (old-good one and new-bad one) using a hex-editor and my first clue is that there are carriage returns in the new file and none in the old one. this may not fix the issue, but I'd like to eliminate it from the equation.
I think I need to remove all the carriage returns from my xml file in order for it to work as I need it to. In my travels, the closest I found is this:
.Replace("\r","")
but where do I use it in the following code? I create my data model, create a root, and pass that to the serializer. At what point can I say "remove carriage returns?"
let def = new reportDefinition("decileRank", "jasper", new template("\\\\server\\location\\filename.jrxml", "jrxml"))
let header = new reportDefinitions([| def |])
let root = reportGenerator(header, new dbConnection(), new reports(reportsArray))
let path = sprintf "C:\\JasperRpt\\parameter_files\\%s\\%d\\%s\\%s\\" report year pmFirm pmName //(System.DateTime.Now.ToString("ddMMyyyy"))
Directory.CreateDirectory(path) |> ignore
let filename = sprintf "%s%s" path month
printfn "%s" filename
use fs = new FileStream(filename, FileMode.Create)
let xmlSerializer = XmlSerializer(typeof<reportGenerator>)
xmlSerializer.Serialize(fs,root)
fs.Close()
XmlWriterSettings has some options for formatting the output, so pass the output through XmlWriter.
You should be able to something like this (don't have FSI at hand right now, don't know if it compiles. :)
//use fs = new FileStream(filename, FileMode.Create)
let settings = new XmlWriterSettings();
settings.Indent <- true;
settings.NewLineChars <- "\n";
use w = XmlWriter.Create(filename, settings);
let xmlSerializer = XmlSerializer(typeof<reportGenerator>)
xmlSerializer.Serialize(w,root)
It's probably not the best solution, but you could try
// after your current code
let xmlString = File.ReadAllText filename
ignore( File.WriteAllText( filename , xmlString.Replace("\r","")))