I am trying to achieve extract the version number of an app. Some rows are missing the app version and i wanted to populate that as well.
post_mobileappid
app_version
My someword 13.0.0
13.0.0
MySomeWord 12.0
12.0
I have the following
MAX(cast(coalesce(nullif(regexp_substr(post_mobileappid, 'My Some (\d\.\d*)', 0, 1, 'e'),''),'0') as double precision)) AS app_version
I am only getting 0 in the app_version column.
Can I please ask if there are ways to extract the full version number and populate something if it is NULL.
Thanks
Related
I use Oracle APEX (v22.1) and on a page I created a (line) chart, but I have the following problem for the visualization of the graphic:
On the y-axis it is not possible to show the values in the format 'hh:mi' and I need a help for this.
Details for the axis:
x-axis: A date column represented as a string: to_char(time2, 'YYYY-MM')
y-axis: Two date columns and the average of the difference will be calculated: AVG(time2 - time1); the date time2 is the same as the date in the x-axis.
So I have the following SQL query for the visualization of the series:
SELECT DISTINCT to_char(time2, 'YYYY-MM') AS YEAR_MONTH --x-axis,
AVG(time2 - time1) AS AVERAGE_VALUE --y-axis
FROM users
GROUP BY to_char(time2, 'YYYY-MM')
ORDER BY to_char(time2, 'YYYY-MM')
I have another problem to solve it in another way: I am not familiar with JavaScript, if the solution is only possible in this way. Because I started new with APEX, but I have seen in different tutorials that you can use JS. So, when JS is the only solution, I would be happy to get a short description what I must do on the page.
(I don't know if this point is important for this case: The values time1 and time2 are updated daily.)
On the attributes of the chart I enabled the 'Time Axis Type' under Settings
On the y-axis I change the format to "Time - Short" and I tried with different pattern like ##:## but in this case you see for every value and also on the y-axis the value '01:00' although the line chart was represented in the right way. But when I change the format to Decimal the values are shown correct as the line chart.
I also tried it with the EXTRACT function for the value like 'EXTRACT(HOUR FROM AVG(time2 - time1))|| ':' || EXTRACT(MINUTE FROM AVG(time2 - time1))' but in this case I get an error message
So where is my mistake or is it more difficult to solve this?
ROUND(TRUNC(avg(time2 - time1)/60) + mod(avg(time2 - time1),60)/100, 2) AS Y
will get close to what you want, you can set Y Axis minimum 0 maximum 24
then 12.23 means 12 hour and 23 minutes.
I am trying to grab the formatted current data and create a variable from it using the command:
gen %tdCY-N-D final_dayinpt = date(c(current_date), "DMY")
However, I am getting an error
%tdCY invalid name
r(198);
If I display this at the Stata command line it works:
. display %tdCY-N-D date(c(current_date), "DMY")
2020-10-27
How can I create this formatted variable?
Solution:
set obs 10 // so the example works
generate final_dayinpt = date(c(current_date), "DMY")
format final_dayinpt %tdCY-N-D
The syntax you're trying is tempting because the format you use for display is seems analogous to things like generate byte bytevar = 1, but, as you found the analogy doesn't hold here.
Note that you are passing format information where type is expected based on the generate syntax (help generate):
generate [type] newvar[:lblname] =exp [if] [in] [, before(varname) | after(varname)]
While consulting help generate and help display are helpful, help datetime is also very useful here (and was never obvious to me).
See here for a more thorough treatment of working with dates in Stata.
Edit:
An alternative suggested (and made possible by) Nick Cox:
ssc install numdate // install the package which Nick wrote
generate current_date = c(current_date) // numdate takes a varlist
numdate daily final_dayinpt = current_date, pattern(DMY) format(%tdCY-N-D)
I'm using pandas.Series.str.replace to extract numbers from strings (its data that has been scraped from #WPWeather) and have got the point where I've extracted all the fields into a DataFrame like this...
df.head()
Out[48]:
temp pressure relative_humidity \
created_at
2019-12-13 10:19:13 5.2\xc2\xbaC, 975.4mb, 91.3%.
2019-12-12 10:19:07 2\xc2\xbaC, 990.3mb, 96.9%.
2019-12-11 10:19:07 4.2\xc2\xbaC, 1000.8mb, 85.7%.
2019-12-10 10:19:00 6.3\xc2\xbaC, 1008.5mb, 94.4%.
2019-12-09 10:18:51 5.4\xc2\xbaC, 1006.7mb, 68.5%.
last_24_max_temp last_24_min_temp rain sunshine
created_at
2019-12-13 10:19:13 7\xc2\xbaC, 2\xc2\xbaC, 9.5mm, 0
2019-12-12 10:19:07 6\xc2\xbaC, 1.5\xc2\xbaC, 0.9mm.' NaN
2019-12-11 10:19:07 11.7\xc2\xbaC, 2.2\xc2\xbaC, 14.1mm.' NaN
2019-12-10 10:19:00 6.5\xc2\xbaC, 1.9\xc2\xbaC, 1.1mm.' NaN
2019-12-09 10:18:51 8.5\xc2\xbaC, 5.2\xc2\xbaC, 1.5mm, 1.9
I'm trying to use regex's to extract the numerical values using...
pd.to_numeric(df['temp'].str.replace(r'(^-?\d+(?:\.\d+)?)(.*)', r'\1', regex=True))
...and it works well but I've hit an instance where one of the temperature fields doesn't have a value and is simply \xc2\xbaC,, as a consequence there is nothing matched in the first grouping to use in r'\1' and when it gets to trying to convert to numeric it fails with...
pandas/_libs/lib.pyx in pandas._libs.lib.maybe_convert_numeric()
ValueError: Unable to parse string "\xc2\xbaC," at position 120
How do I replace non-matches with something sane such as blank so that when I then call pd.to_numeric() it will convert to NaN?
Onde idea is change string for replace, then got not exist values get missing values:
df['temp'] = pd.to_numeric(df['temp'].str.replace(r'\xc2\xbaC,', '', regex=True))
print (df)
temp pressure relative_humidity
created_at
2019-12-13 10:19:13 5.2 975.4mb, 91.3%.
2019-12-12 10:19:07 2.0 990.3mb, 96.9%.
2019-12-11 10:19:07 4.2 1000.8mb, 85.7%.
2019-12-10 10:19:00 6.3 1008.5mb, 94.4%.
2019-12-09 10:18:51 5.4 1006.7mb, 68.5%.
Your solution should be changed with parameter errors='coerce' in to_numeric for replace non numeric to missing values:
df['temp'] = (pd.to_numeric(df['temp'].str.replace(r'(^-?\d+(?:\.\d+)?)(.*)',r'\1',regex=True),
errors='coerce'))
activerecord 4.2.11.1
activerecord-jdbc-adapter 1.3.25
activerecord-jdbcpostgresql-adapter 1.3.25
jdbc-postgres 9.4.1206
The following method call returns a Date when using ruby 2.3.3 but returns a String when using JRuby-9.1.17.0 with activerecord-jdbcpostgresql-adapter :
2.3.3 :017 > Table.select('now() as date').first.date
Table Load (0.7ms) SELECT now() as date FROM "tables" ORDER BY "tables"."id" ASC LIMIT 1
=> 2019-05-17 03:46:52 UTC
jruby-9.1.17.0 :002 > Table.select('now() as date').first.date
Table Load (2.0ms) SELECT now() as date FROM "tables" ORDER BY "tables"."id" ASC LIMIT 1
=> "2019-05-17 03:48:57.572526+00"
This only happens if the selected attribute does not exist in the database:
2.3.3 :012 > Table.select(:created_at).first.created_at
Table Load (0.6ms) SELECT "tables"."created_at" FROM "tables" ORDER BY "tables"."id" ASC LIMIT 1
=> Wed, 25 Sep 2013 14:26:17 -03 -03:00
jruby-9.1.17.0 :019 > Table.select(:created_at).first.created_at
Table Load (0.8ms) SELECT "tables"."created_at" FROM "tables" ORDER BY "tables"."id" ASC LIMIT 1
=> Wed, 25 Sep 2013 14:26:17 -03 -03:00
This happens with either WebRick or Tomcat 7. This error does not occur with the same version of activerecord-jdbc-adapter if using Active Record 4.0 or 4.1. Upgrading to latest jruby-9.2.7.0 did not help either.
seems like a compatibility bug in AR-JDBC, at this point likely a won't fix as AR 4.2 also isn't supported.
you should try upgrading to 5.x if this is an issue or try resolving the problem and submit a PR ...
as a last resort try setting ActiveRecord::ConnectionAdapters::JdbcConnection.raw_date_time = true (altough I think its already truewhen running on AR 4.2)
as #kares noted, this look like a bug, also it is related to the configuration ActiveRecord::ConnectionAdapters::JdbcConnection.raw_date_time. Its seems like if it is set to true the method call below returns a String, otherwise it returns a Time instance:
Locatario.select('now() as date').first.date
I have checked this behaviour with 3 versions of active_record:
Rails 3.2
default raw_date_time? == true
Table.select('now() as date').first.date
Ruby: returns String
JRuby: returns String
Rails 4.0/4.1
default raw_date_time? == nil
Table.select('now() as date').first.date
Ruby: returns Time
JRuby: returns Time
Rails 4.2
default raw_date_time? == true
Table.select('now() as date').first.date
Ruby: returns Time
JRuby: returns String
So, it looks like to emulate active_record >= 4.0 the gem activerecord-jdbc-adapter should use raw_date_time = false, because it should return a Time instance with the method call in question. As a workaround I created a file with the following content under initializers:
if RUBY_PLATFORM == "java" && Rails::VERSION::STRING.starts_with?("4.2.")
ActiveRecord::ConnectionAdapters::JdbcConnection.raw_date_time = false
end
I am attempting to add a simple text string (glyph) to a Bokeh plot which uses x_axis_type='datetime'
My code (stripped to its essentials ) is as follows:
p = figure(plot_width=900, plot_height=380, x_axis_type='datetime')
dt = date(2003, 3, 15)
p.line(xvals, yvals)
txt = Text(
# x=some_formatting_function(dt),
x=1057005600000,
y=0.1,
text=["happy day!"],
text_align="left",
text_baseline="middle",
text_font_size="11pt",
text_font_style="italic",
)
p.add_glyph(txt)
show(p)
The x-axis range/values (ie dates) run from 2002 to 2006 and I'd like to add the text in, say, 2003. The x value I've shown in the code above (ie 1057005600000 -- which I've worked out by trial and error) drops the glyph in the right place.
But I cant work out how to use a datetime.date directly...
Is there a bokeh function (or a property of datetime.date) that will give me the value which the bokeh plot is expecting??
Many thanks.
N.B. I've tried using x = bokeh.properties.Date(dt) but this gives me:
ValueError: expected an element of either String,
Dict(String, Either(String, Float)) or Float, got <bokeh.properties.Date object
When the x_axis_type attr is set to 'datetime', Bokeh will plot things along the x-axis according to seconds-since-epoch. The easiest solution is to use datetime.datetime (not .date) and then cast your dt object to seconds-since-epoch using the timestamp() method (which will give the ~1.50e9 number you're getting) then use that for your x-coordinate.
$ from datetime import datetime
$ dt = datetime.now()
$ dt
> datetime.datetime(2015, 6, 17, 10, 41, 34, 617709)
$ dt.timestamp()
> 1434555694.617709
See the following SO question/answer for the python2 answer to my problem:
How can I convert a datetime object to milliseconds since epoch (unix time) in Python?
Thank you #Luke Canavan for pointing me in the right direction(!)