CodenameOne: Bug in Double.parseDouble on iOS - codenameone

The following code :
String test1 = "1.000000108001807564";
String test2 = "1.0000001080018075648";
System.out.println(test1 + " -> " + Double.parseDouble(test1));
System.out.println(test2 + " -> " + Double.parseDouble(test2));
works correctly in the simulator and on Android:
1.000000108001807564 -> 1.0000001080018075
1.0000001080018075648 -> 1.0000001080018075
But fails on iOS:
1.000000108001807564 -> 1.0
1.0000001080018075648 -> -1.183888

Related

Change font weight in a WPF label only for some parts

I have a calculator and the results are shown in a label. Is it possible to set the result values (some string, some double) to display in bold?
My code looks like this:
...{
label2.Content = "your time: " + saldoMin +
" and: " + fooNeg +
" " + inH +
" : " + inMin +
" [h : min]\nyour factor: " + YourFactor +
"\n\ngo at: " + beginnH +
" : " + fooNull;
}
and I only want the objects saldoMin, fooNeg, inH, ... to be bold, but not the code behind.
You can use a TextBlock with Runs. Here is an example:
var text = new TextBlock();
text.Inlines.Add(new Bold(new Run("Bold:")));
text.Inlines.Add(new Run(" nonbold"));
label2.Content = text;

Apache Flink: What type of record does JDBCInputFormat return?

I am getting an error related to setRowTypeInfo for a JDBCInputFormat. The error is below. Clearly the Tuple2 type of the DataSet doesn't like the RowTypeInfo of the JDBCInputFormat but I can't find anywhere that provides clarification on how to define the format.
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
(default-compile) on project flink: Compilation failure [ERROR]
/Users/rocadmin/Desktop/flink/flink/src/main/java/svalarms/BatchJob.java:[125,48]
incompatible types: inferred type does not conform to equality
constraint(s) [ERROR] inferred:
org.apache.flink.api.java.tuple.Tuple2
[ERROR] equality constraints(s):
org.apache.flink.api.java.tuple.Tuple2,org.apache.flink.types.Row
[ERROR] [ERROR] -> [Help 1]
DataSet< Tuple2<Integer, Integer> > dbData =
env.createInput(
JDBCInputFormat.buildJDBCInputFormat()
.setDrivername("oracle.jdbc.driver.OracleDriver")
.setDBUrl("jdbc:oracle:thin:#//[ip]:1521/sdmprd")
.setQuery("" +
"SELECT T2.work_order_nbr, T2.work_order_nbr " +
"FROM sdm.work_order_master T2 " +
"WHERE " +
"TO_DATE(T2.date_entered + 19000000,'yyymmdd') >= CURRENT_DATE - 14 " +
"AND T2.W_O_TYPE = 'TC' " +
"AND T2.OFFICE_ONLY_FLG = 'N' " +
"")
.setRowTypeInfo(new RowTypeInfo(BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.INT_TYPE_INFO))
.finish()
);
A JDBCInputFormat returns records of type Row. Hence, the resulting DataSet should be typed to Row, i.e.,
DataSet<Row> dbData =
env.createInput(
JDBCInputFormat.buildJDBCInputFormat()
.setDrivername("oracle.jdbc.driver.OracleDriver")
.setDBUrl("jdbc:oracle:thin:#//[ip]:1521/sdmprd")
.setQuery(
"SELECT T2.work_order_nbr, T2.work_order_nbr " +
"FROM sdm.work_order_master T2 " +
"WHERE " +
"TO_DATE(T2.date_entered + 19000000,'yyymmdd') >= CURRENT_DATE - 14 " +
"AND T2.W_O_TYPE = 'TC' " +
"AND T2.OFFICE_ONLY_FLG = 'N' "
)
.setRowTypeInfo(Types.ROW(Types.INT, Types.INT))
.finish()
);
got it going
TypeInformation[] fieldTypes = new TypeInformation[] {
BasicTypeInfo.BIG_DEC_TYPE_INFO,
BasicTypeInfo.BIG_DEC_TYPE_INFO
};
RowTypeInfo rowTypeInfo = new RowTypeInfo(fieldTypes);
JDBCInputFormatBuilder inputBuilder =
JDBCInputFormat.buildJDBCInputFormat().setDrivername("oracle.jdbc.driver.OracleDriver").setDBUrl("jdbc:oracle:thin:#//ipaddress:1521/sdmprd").setQuery("" +
"SELECT T2.work_order_nbr , T2.work_order_nbr " +
"FROM sdm.work_order_master T2 " +
"WHERE " +
"TO_DATE(T2.date_entered + 19000000,'yyyymmdd') >= CURRENT_DATE - 14 " +
"AND T2.W_O_TYPE = 'TC' " +
"AND T2.OFFICE_ONLY_FLG = 'N' " +
"").setRowTypeInfo(rowTypeInfo).setUsername(“user”).setPassword(“pass”);
DataSet<Row> source = env.createInput(inputBuilder.finish());

creating a file in google cloud storage - IOError: Buffer is closed

I created a python script to pull the data from facebookads API and create a file in google cloud storage by using google app engine.
getting the following error while writing the data to google cloud storage but data is displaying properly on web browser:
IOError: Buffer is closed.
After some research I understood that, this error will come when not able to recognize end of the lin ("\n") , so it treats the entire file as a single line and raise "Buffer is Closed" error.
So I added following code and now displaying rows properly on web browser but still getting error while writing into gcs.
data1=data.replace("\n", "<br />")
Code:
class get_region_insights(webapp.RequestHandler):
_apptitle = None
_projectid = None
_projectnumber = None
def get(self):
#bucket_name = os.environ.get('BUCKET_NAME', app_identity.get_default_gcs_bucket_name())
cfg=appsettings()
for i in cfg._templates:
id=int(i['_id'])
if id == 7:
### Read variables from config file
bucket_name = i['_gcsbucket']
bucket = '/' + bucket_name
filename = bucket + '/' + i['_filename'] + str(time.strftime("%d_%m_%Y")) + ".csv"
ad_acct=i['_ad_acct']
app_id = i['_app_id']
app_secret = i['_app_secret']
access_token = i['_access_token']
needed_keys=ast.literal_eval(i['_needed_keys'])
self.tmp_filenames_to_clean_up = []
u = date.today()
sub_days = 1
s = u - timedelta(sub_days)
until = str(u)
since = str(s)
params = {
'fields': [
FBAdsInsights.Field.account_id,
FBAdsInsights.Field.campaign_id,
FBAdsInsights.Field.campaign_name,
FBAdsInsights.Field.adset_id,
FBAdsInsights.Field.adset_name,
FBAdsInsights.Field.impressions,
FBAdsInsights.Field.spend,
FBAdsInsights.Field.actions,
FBAdsInsights.Field.action_values,
],
'filtering': [
{
'field': 'action_type',
'operator': 'IN',
'value': ["link_click","comment", "post_reaction", "post", "offsite_conversion.fb_pixel_purchase"] #custom rule filter
},
],
'level': 'adset',
'time_range': {
'since': since, #user input field
'until': until #specify dynamic date range between (today() - (days_entered)) and today()
},
'time_increment': 1,
'breakdowns': ['region'],
'action_breakdowns': ['action_type'],
}
### Initializing Google cloud Storage Object
write_retry_params = _gcs.RetryParams(backoff_factor=1.1)
gcs_file=_gcs.open(filename, 'w', content_type='text/plain',retry_params=write_retry_params)
### Facebook Initialization
session=FacebookSession(app_id,app_secret,access_token)
api=FacebookAdsApi(session)
FacebookAdsApi.set_default_api(api)
ad_account = FBAdAccount(ad_acct)
stats = ad_account.get_insights(params=params,async=True)
stats.remote_read()
while stats[AdReportRun.Field.async_percent_completion] < 100:
time.sleep(1)
stats.remote_read()
time.sleep(1)
stats1 = stats.get_result()
x = [x for x in stats1]
### Printing the result and writing to Google Cloud Storage
for i in x:
for k in i['actions']:
if k['action_type'] == "offsite_conversion.fb_pixel_purchase":
Purchase_Facebook_Pixel = k['value']
if k['action_type'] == "comment":
post_comment= k['value']
if k['action_type'] == "link_click":
link_click=k['value']
if k['action_type'] == "post":
post_share=k['value']
if k['action_type'] == "post_reaction":
post_reaction=k['value']
for m in i['action_values']:
if m['action_type'] == "offsite_conversion.fb_pixel_purchase" :
Purchase_Conversion_Value_Facebook_Pixel=m['value']
data=(i['account_id'] + "," + i['adset_id'] + "," + i['campaign_id'] + "," + i['date_start'] + "," + i['date_stop'] + ","+ i['impressions']+ "," + i['region'] + ","+ i['spend']+ "," + link_click + "," + Purchase_Facebook_Pixel + "," + Purchase_Conversion_Value_Facebook_Pixel+"\n")
data1=data.replace("\n", "<br />")
self.response.write(data.replace("\n", "<br />"))
#self.response.write("\n"+i['account_id'] + "," + i['adset_id'] + "," + i['adset_name'] + "," + i['age'] + "," + i['campaign_id'] + "," +i['campaign_name'] + "," + i['date_start'] + "," + i['date_stop'] + ","+i['gender'] + ","+ i['impressions']+","+ i['spend']+ "," + link_click + "," + post_comment + "," + post_share + "," + post_reaction + "," + Purchase_Facebook_Pixel + "," + Purchase_Conversion_Value_Facebook_Pixel+"\n")
gcs_file.write(data1.encode('utf-8'))
gcs_file.close()
self.tmp_filenames_to_clean_up.append(filename)
You are opening the cloud storage file outside your loop, but then you close inside the loop.
### Initializing Google cloud Storage Object
write_retry_params = _gcs.RetryParams(backoff_factor=1.1)
gcs_file=_gcs.open(filename, 'w', content_type='text/plain',retry_params=write_retry_params)
### Facebook Initialization
...
### Printing the result and writing to Google Cloud Storage
for i in x:
# do stuff with data
...
gcs_file.write(data1.encode('utf-8'))
gcs_file.close() # <-- closing the file buffer
self.tmp_filenames_to_clean_up.append(filename)
If you want to write one file for each loop iteration, open and close the file inside the loop.
If you want to to write all the data to a single file, open and close the file outside the loop.

How can i set this path in java?

I want to execute a batch command via java.
how can I do that ?
"c:\windows\system32\net use s: \192.168.1.160"\100 Gelem 1" /user:xxx xxx"
this one actually works on windows command prompt
the code I tries witout success is :
String[] cmd = { "c:\\windows\\system32\\net","use s: \\\\192.168.1.160\"\\100 Gelem 1 \" /user:100 100"};
Process p = Runtime.getRuntime().exec(cmd);
ProcessBuilder builder = new ProcessBuilder(cmd);
builder.redirectErrorStream(true);
p.waitFor();
I finally worked it out !!!
cmd1 = "c:\\windows\\system32\\net.exe " + "use" + " s:" +
" \"\\\\192.168.1.160\\100 Gelem 1\"" + " /user:100" + " 100";
String[] cmd = {cmd1};

Why does Sleep(); function skip Label -> Text commands?

In my Programming I have made two Attack logs (they are labels) which display things that happen during a battle... But whenever I run the code, both labels skip all previous code and display the last thing that It was told to display...
this -> EnemyAttackLog -> Text = "[Enemy Attack Log] " + EName + " Attacked!!";
Sleep(500);
damage = rnd4 -> Next(-2,3) + EnemyA;
if (D > EnemyA)
{
damage = rnd4 -> Next(3,6);
this -> AttackLog -> Text = "[Attack Log] Your Armor Reduced the Damage!";
}
Sleep(500);
this -> EnemyAttackLog -> Text = "[Enemy Attack Log] " + EName + " did " + damage + " Damage";
Hp -= damage;
this -> HealthBar -> Value = Hp;
Sleep(800);
damage = rnd4 -> Next(-2,3) + A;
if (EnemyD > A)
{
damage = rnd4 -> Next(3,6);
this -> EnemyAttackLog -> Text = "[Enemy Attack Log] " + EName + "'s armor reduced damage!";
}
Sleep(1500);
this -> AttackLog -> Text = "[Attack Log] " + Name + " did " + damage + " Damage";
EnemyHp -= damage;
this -> EnemyHealth -> Value = EnemyHp;
If this did what i thought it would do, It would display
this -> EnemyAttackLog -> Text = "[Enemy Attack Log] " + EName + " Attacked!!";
for Half a second and move on to display the next code for Another half a second, But instead, all it does is wait for ALL the sleep functions (Which added together makes 3300 milliseconds) and THEN displays the text at the very end... which is
this -> AttackLog -> Text = "[Attack Log] " + Name + " did " + damage + " Damage";
Why does it skip all previous commands (for the labels text) but STILL waits for 3300 milliseconds?
It is probably down to the fact you are sleeping the UI thread. I've just tried a similar test in C# and I get the same issue. To fix this you will have to call Refresh on the textbox after setting the value.
Another way would be to do the work on a background thread and then marshal the "this->EnemyAttackLog->Text = sometext" code onto the UI thread. This way your UI will stay responsive.

Resources