€ Symbol from commandline (Arguments) - eiffel

I have a simple euro_to_dm command line program written but the "€" symbol doesn't work. The example change every time "dm to euro" but not "€ to dm". Sorry for my English.
Ubuntu 19.4 ise-eiffel AND liberty-eiffel
class EURO
inherit ARGUMENTS_32
create {ANY}
make
feature {ANY}
make
do
works_not
end
works_not
local ok: BOOLEAN
do
print ("%N%NAnzahl Argumente : " + argument_count.out + "%N")
print ("%NArgument -> Programmname : " + argument(0))
print ("%NArgument -> Wert : " + argument(1))
print ("%NArgument -> Währung : " + argument(2) + "%N")
ok := argument(2).is_equal("€")
print ("%NArgument(2) ist Euro ? " + ok.out + "%N%N")
print ("don't work")
io.put_new_line
if argument(2).is_equal("€") then
euro_in_dm(argument(1).to_real)
else
dm_in_euro(argument(1).to_real)
end
end
feature {ANY}
euro_in_dm (a: REAL)
do
io.put_string("%N Euro -> DM ")
io.put_real(a * 1.95583)
io.put_string("%N%N")
end
dm_in_euro (a: REAL)
do
io.put_string("%N DM -> Euro ")
io.put_real(a / 1.95583)
io.put_string("%N%N")
end
end

To create manifest Unicode string, you should use {STRING_32} "€"
To compare strings, you'd better use same_string, i.e
if s.same_string ({STRING_32} "€") then ...
Note the syntax for manifest Unicode character using the hexadecimal value is {CHARACTER_32} '%/0x20AC/'
To output Unicode in console/terminal, it is better to use the LOCALIZED_PRINTER from the encoding library.
see https://www.eiffel.org/blog/jocelyn_fiat/lets_talk_about_the_encoding_library#Write_unicode_into_the_console

Here the program that works (this is in spanish). You should include the library encoding to your project. You cannot show the symbol € with print, you should use localized_print.
class
EURO
inherit
ARGUMENTS_32
LOCALIZED_PRINTER
create
make
feature {ANY}
make
do
works_not
end
works_not
local ok: BOOLEAN
do
print ("%N%NArgumentos : " + argument_count.out + "%N")
print ("%NArgument -> Programa : " + argument(0) + "%N")
print ("%NArgument -> Valor : " + argument(1) + "%N")
localized_print ({STRING_32} "%NArgument -> Moneda : " + argument(2) + {STRING_32} "%N")
ok := argument(2).item(argument(2).lower).is_equal ('%/0x000020AC/')
print ("%NArgument(2) ist Euro ? " + ok.out + "%N%N")
if ok then
euro_in_dm(argument(1).to_real)
else
dm_in_euro(argument(1).to_real)
end
end
feature {ANY}
euro_in_dm (a: REAL)
do
io.put_string("%N Euro -> DM ")
io.put_real(a * 1.95583)
io.put_string("%N%N")
end
dm_in_euro (a: REAL)
do
io.put_string("%N DM -> Euro ")
io.put_real(a / 1.95583)
io.put_string("%N%N")
end

Related

How to save Array[String, Int] data into file

I am trying to save a Array[String, Int] data into file. However, every time, it reports:
object not serializable
I also tried to combine the two columns into a string, and want to write it line by line, but it still report such error. The code is:
val fw = new PrintWriter(new File("/path/data_stream.txt"))
myArray.foreach(x => fw.write((x._1.toString + " " + x._2.toString + "\n").toByte
import java.nio.file._
val data = Array(("one", 1), ("two", 2), ("three", 3))
data.foreach(d => Files.write(Paths.get("/path/data_stream.txt"), (d._1 + " " + d._2 + "\n").getBytes, StandardOpenOption.CREATE, StandardOpenOption.APPEND))

Why it gives me Type error in that code?

Why he gives me (Type error) in that statment
" address = cur.fetchone()[2] last = cur.fetchone()[4] no = cur.fetchone()[5] , while it accept "name = cur.fetchone()[1]" in the code : "
import sqlite3
conn = sqlite3.connect('myproject.sqlite')
cur = conn.cursor()
print "Welcome Mr/Hefnawy"
cur.execute('SELECT phone FROM participants')
b = cur.fetchone()[0]
while True:
a = raw_input("Enter Phone number here : ")
if a == b :
cur.execute('SELECT name,address,last_order,no_of_orders FROM participants WHERE phone = ?',(b, ))
name = cur.fetchone()[1]
address = cur.fetchone()[2]
last = cur.fetchone()[4]
no = cur.fetchone()[5]
print "The Costumer is already exist in Paricipants "
print "To edit the costumer data press (1)", "\n" , "to delet the costumer press (2)", "\n" , "add new order to the costumer press (3) "
c = raw_input("Enter your choice here : ")
if c == "1":
print "What do you want to edit ? , to edit name press 1 , to edit address press 2 , to edit phone press 3"
d = raw_input("Enter your choice here : ")
if d == "1" :
e = raw_input("New costumer name please ")
cur.execute('UPDATE participants SET name = ? WHERE phone = ?' , (e , a))
print "Costumer name has been updated to :", e
print ""
conn.commit()
else:
print "The costumer is not exist"
print b
print a , type(a)
When you are fetching something from a cursor say for example
t = cur.fetchone()
you can access the data from t using
print t[0],t[1],t[2] but In your case you are using multiple cur.fetchone() which allows you to use name = cur.fetchone()[1] that ends the data in the cursor. The second line address = cur.fetchone()[2] and the lines that follow it do not have a sql query executed for them to fetch, hence giving you the error. If you want to access the whole row just assign it to a variable and use the variable to get the data.

Date and Time Format in SSIS

I have a date and time format:
Interval Start Time
1/13/16 1:30:00
1/15/16 10:30:00
Desired Result
Interval Start Time
13/01/2016 13:30:00 (24 Hr)
15/01/2016 10:30:00
The Interval Time is between 08:00 to 17:30.
I would like it to be: 13/01/2016 13:30 and 15/01/2016 10:30:00 and I devised this In SSIS derived Column:
(DT_DATE)(SUBSTRING([Interval Start Time],3,2) + "-" +
SUBSTRING([Interval Start Time],1,1) + "-" +
SUBSTRING([Interval Start Time],6,2) + " " +
SUBSTRING([Interval Start Time],9,1) == 1 ? "13" :
SUBSTRING([Interval Start Time],9,1) == 2 ? "14" :
SUBSTRING([Interval Start Time],9,1) == 3 ? "15" :
SUBSTRING([Interval Start Time],9,1) == 4 ? "16" :
SUBSTRING([Interval Start Time],9,1) == 5 ? "17" :
"[Interval Start Time]" )
+ ":" + SUBSTRING([Interval Start Time],11,2))
The error I get in SSIS is:
...The expression might contain an invalid token, an incomplete token, or an invalid element...
and I am not sure if the formula is correct in what I want it to do either. Any help would be much appreciated.
Before present a possible solution here, I want you be aware about some errors in your approach. Using expressions for this requeriment is very complex and hard to maintain, besides what happen when your Interval Start Time column have dates from October (10) to December (12) months, your string lenght will change and your hardcoded solution via SUBSTRING calls will return absurd data and produce error while package is running.
SOLUTION: Use Script component.
After creating your source, add a Script Component and link the source to it.
Configure the Script component to include Interval Start Time column by selecting it in Input Columns tab.
Add an output column, name it as you want and choose database timestamp (DT_DBTIMESTAMP).
Go to Script tab, and press the Edit Script... button.
Use the below code to overwrite the Input0_ProcessInputRow function.
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
/*
* Add your code here
*/
var str_timestamp = Row.IntervalStartTime.ToString();
string[] arr = str_timestamp.Trim().Split(' ');
string[] date = arr[0].Split('/');
string[] time = arr[1].Split(':');
string formatedDate = "20" + date[2] + "-" + date[0].PadLeft(2, '0') + "-" + date[1].PadLeft(2, '0');
int hour = Convert.ToInt32(time[0]);
int hour_24 = hour < 8 ? hour + 12 : hour;
formatedDate += " " + hour_24 + ":" + time[1] + ":" + time[2];
Row.MyColumn = Convert.ToDateTime(formatedDate);
}
In Row.MyColumn, replace MyColumn by the given name of your output column.
Save changes in Visual Studio and close the editor.
Now you can add a destination after the Script component and you will see the formatted IntervalStartTime as you need.
Let me know if this helps.

how to create pymol rename loop

I would like to create a loop for changing interactions name in PyMol. But after one selection loop it crashes and doesn't work.
def get_dists(interactions): # interactions=([1,2], [3,4])
for i in interactions:
a = "////" + str(i[0]) + "/C2'"
b = "////" + str(i[1]) + "/C2'"
cmd.distance("(" + a + ")", "(" + b + ")")
for j in range(1, 599):
x = "dist" + "0" + str(j)
y = str(i[0]) + " " + str(i[1])
cmd.set_name(str(x), str(y))
In Pymol the default name of interactions is dist01, 02 , 03.
I want to change these to 1_3, 5_59, 4_8, (interaction between residue).
Your code is totally fine except for one thing: If PyMol doesn't succeed with set_name the whole script is aborted. When you change it to, it should work:
try:
cmd.set_name(str(x), str(y))
except:
print('failed to rename')
Some additional comments:
y = str(i[0]) + " " + str(i[1]) should be y = str(i[0]) + "_" + str(i[1])
this line is probably for padding zeros x = "dist" + "0" + str(j). This is only needed when j is a single digit, otherwise the name of the distance objects is dist20 or dist123
cmd.set_name(str(x), str(y)) can be simplified to cmd.set_name(x, y) since x and y are already strings.

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