Birt data cube column sorting - sorting

I am trying to sort the datacube on the Aging Group column to appear in the following order 1-30, 31-60, 61-90 etc image located here - https://i.stack.imgur.com/Caoj8.jpg
I initially thought I would modify the sort option for ascending but it did not work. I tried to modify the data from "string" to "float", but I have one category listed as "Not Aged" (equivalent to 0) and it triggers errors.
I have built an expression to create a custom sort on the datacube, but it does not seem to be working.
var pattern = /^[N]/gi;
if (dimension["Group1"]["CATEGORY_DESCRIPTION"] == 'Not Aged'){1}
else if (dimension["Group1"]["CATEGORY_DESCRIPTION"] == '1-30'){2}
else if (dimension["Group1"]["CATEGORY_DESCRIPTION"] == '31-60'){3}
else if (dimension["Group1"]["CATEGORY_DESCRIPTION"] == '61-90'){4}
else if (dimension["Group1"]["CATEGORY_DESCRIPTION"] == '91-120'){5}
else if (dimension["Group1"]["CATEGORY_DESCRIPTION"] == '121-150'){6}
else if (dimension["Group1"]["CATEGORY_DESCRIPTION"] == '151-180'){7}
else if (dimension["Group1"]["CATEGORY_DESCRIPTION"] == '181-210'){8}
else if (dimension["Group1"]["CATEGORY_DESCRIPTION"] == '211-240'){9}
else if (dimension["Group1"]["CATEGORY_DESCRIPTION"] == '241-270'){10}
else if (dimension["Group1"]["CATEGORY_DESCRIPTION"] == '271-300'){11}
else if (dimension["Group1"]["CATEGORY_DESCRIPTION"] == '331-365'){12}
else if (dimension["Group1"]["CATEGORY_DESCRIPTION"] == '331-365'){13}
else if (dimension["Group1"]["CATEGORY_DESCRIPTION"] == '366+'){14}
else {99}
The data is still displaying as per the screen shot and since "Not Aged" is 0 I'd like for it to be listed first.
Any suggestions on how to fix this issue?

I was finally able to figure it out!
On the datacube in the actual row cell -- I mapped the Not Aged to display as 0
On the datacube I then added an attribute of "age" to the Category Description. I was then able to sort on the DataCube using the following: dimension["Group1"]["CATEGORY_DESCRIPTION"]["DISCHARGE_AGE"] in the Ascending order.

Related

How to return to beginning of program from inside of if statement?

I'm practicing some basic coding, I'm running a simple math program running in the terminal on Visual Studio Code.
How do I create an option to return to the beginning of the program, or exit the program after getting caught in an if statement?
Example:
#beginning of program
user_input=input('Please select "this" or "that": ')
findings=user_input
If findings == this:
print(this)
# How can I redirect back to first user input question, instead
# of just ending here?
if findings == that:
print (that)
# Again, How do I redirect back to first user input, instead of
# the program ending here?
# Can I setup a Play_again here with options to return to user_input,
# or exit program? And then have all other If statements
# redirect here after completion? How would I do that? with
# another If? or with a for loop?
#end program
You can try wrapping the whole program in a while loop like this:
while(True):
user_input=input('Please select "this" or "that": ')
this = 'foo'
if user_input == this:
print(this)
continue
if user_input == this:
print(this)
continue
Unfortunately, that 'another technique' I thought of using didn't work.
Here's the code (the first example modified):
import sys
def main():
# Lots of setup code here.
def start_over():
return #Do nothing and continue from the next line
condition = 1==1 #Just a sample condition, replace it with "check(condition)".
float_condition = condition
def play(*just_define:bool):
if not just_define:
play_again = input('play again? "y" or "n"')
if play_again == 'y':
start_over() #Jump to the beginning of the prohram.
if play_again == 'n':
sys.exit() #Exit the program
while True:
if float_condition == True:
# print(float_condition)
play() #skip to play_again from here?
if float_condition == False:
#print(float_condition)
play() #skip to play_again from here?
#I removed the extra "main()" which was here because it'd cause an infinite loop-like error.
main()
Output:
play again? "y" or "n"y
play again? "y" or "n"n
Process finished with exit code 0
The * in the play(*just_define:bool) function makes the just_define parameter optional. Use the parameter if you want to only tell Python to search for this function, so it doesn't throw a ReferenceError and not execute anything that's after the line if not just_define:. How to call like so: play(just_define=True).
I've used nested functions. I've defined play so that you can call it from other places in your code.
Thanks to #Hack3r - I was finally able to choose to return back to the beginning of the program or exit out. But it resulted in a new issue. Now my print(results) are printing 4 or 5 times...
Here is the actual code I built and am working with:
def main():
math_Options=['Addition +','Subtraction -','Multiplication *','Division /']
math_func=['+','-','*','/']
for options in math_Options:
print(options)
print('Lets do some Math! What math function would you like to use? ')
while True:
my_Math_Function = input('Please make your choice from list above using the function symbol: ')
my_Number1=input('Please select your first number: ')
x=float(my_Number1)
print('Your 1st # is: ', x)
my_Number2=input('Please select your Second Number: ')
y=float(my_Number2)
print('Your 2nd # is: ', y)
z=float()
print('')
for Math_function in math_func:
if my_Math_Function == math_func[0]:
z=x+y
if my_Math_Function == math_func[1]:
z=x-y
if my_Math_Function == math_func[2]:
z=x*y
if my_Math_Function == math_func[3]:
z=x/y
if (z % 2) == 0 and z>0:
print(z, ' Is an EVEN POSITIVE Number')
if (z % 2) == 1 and z>0:
print(z, ' IS a ODD POSTIVE Number')
if (z % 2) == 0 and z<0:
print(z, ' Is an EVEN NEGATIVE Number')
if (z % 2) ==1 and z<0:
print(z, ' IS a ODD NEGATIVE Number')
if z==0:
print(z, 'Is is Equal to Zero')
print('')
play_again=input('Would you like to play again? "y" or "n" ')
if play_again == 'y':
continue
if play_again == 'n':
break
main()
main()

Rosalind Translating RNA into Protein problem

Hello i tried doing this problem from ROSALIND but when i put the example rna sequence (AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA) it produced me the wrong output "['M', 'M', 'N', 'I']" instead of the suggested "MAMAPRTEINSTRING".I tried to modify the code but still not it did not give me the desired output.I would like some help if someone can.
Here is my code:
**dna_seq = input("PLace your RNA sequence here(it must not exceed 1kb):")
list = []
for x in range (0,len(dna_seq),3):
if dna_seq[x:x+3] == "AUG":
list.append("M")
elif dna_seq[x:x+3] == ("UUU" or "UUC"):
list.append("F")
elif dna_seq[x:x+3] == ("UUA" or "UUG" or "CUU" or "CUC" or "CUA" or "CUG"):
list.append("L")
elif dna_seq[x:x+3] == ("AUU" or "AUC" or "AUA"):
list.append("I")
elif dna_seq[x:x+3] == ("GUA" or "GUG" or "GUC" or "GUU"):
list.append("V")
elif dna_seq[x:x+3] == ("UCA" or "UCU" or "UCG" or "UCC"):
list.append("S")
elif dna_seq[x:x+3] == ("CCU" or "CCA" or "CCC" or "CCG" or "AGU" or "AGC"):
list.append("P")
elif dna_seq[x:x+3] == ("ACA" or "ACU" or "ACG" or "ACC"):
list.append("T")
elif dna_seq[x:x+3] == ("GCU" or "GCA" or "GCG" or "GCC"):
list.append("A")
elif dna_seq[x:x+3] == ("UAU" or "UAC"):
list.append("Y")
elif dna_seq[x:x+3] == ("UAA" or "UAG" or "UGA"):
list.append("STOP")
elif dna_seq[x:x+3] == ("CAU" or "CAC"):
list.append("H")
elif dna_seq[x:x+3] == ("CAA" or "CAG"):
list.append("Q")
elif dna_seq[x:x+3] == ("AAU" or"AAC"):
list.append("N")
elif dna_seq[x:x+3] == ("AAA" or "AAG"):
list.append("K")
elif dna_seq[x:x+3] == ("GAU" or "GAC"):
list.append("D")
elif dna_seq[x:x+3] == ("GAA" or "GAG"):
list.append("E")
elif dna_seq[x:x+3] == ("UGU" or "UGC"):
list.append("C")
elif dna_seq[x:x+3] == ("UGG"):
list.append("W")
elif dna_seq[x:x+3] == ("CGA" or "CGG" or "CGC" or "CGU" or "AGA" or "AGG"):
list.append("R")
elif dna_seq[x:x+3] == ("GGU" or "GGC" or "GGA" or "GGG"):
list.append("G")
print(list)**
Thanks for your time!
The statement ("CAU" or "CAC") evaluates to "CAU".:
>>> ("CAU" or "CAC")
'CAU'
Thus your elif statements will only ever check the first codon in the list. You can fix this by rewriting your statements to this format:
elif dna_seq[x:x+3] == "CAU" or dna_seq[x:x+3] "CAC":
But much better would be to make a dictionary where your codons are the keys and the values are the amino acids corresponding to that codon. Then build your protein sequence by getting the value of a codon from the dictionary and add it your list.
Finally, don't name a variable in python list. It overwrites the built in function list().

How can i replace true and false with 1 and 0 exporting to txt

im new to rails and it seems like a really easy problem, but i dont get it.
So i want to extrakt a .txt file out of my database. I want to export the boolean data with "true" and "false" as "0" and "1". Here is my code:
if File.exist?("nanny_Input.inc")
File.delete("nanny_Input.inc")
end
f=File.new("nanny_Input.inc", "w")
printf(f, "parameter FV(i) / \n")
#nannies = Nanny.all
#nannies.each { |nann|
printf(f, nann.name + "\s" + nann.fuehrerschein.to_s + "\n") }
printf(f, "/;\n\n")
And nann.fuehrerschein ist boolean so i just want the output "0" and "1". Sorry for such an easy question but it would be nice if someone of you help me :) Thank you!!!
just check if the boolean value is true or false. You can make use of ternary operator in this case
printf(f, "#{nann.name} #{nann.fuehrerschein ? 1 : 0}\n") }
Here is how this will work -
For each record it will check if nann.fuehrerschein == true
If the condition is true it will return 1
Else it will return 0
Also, you can change your code a bit
File.open('nanny_Input.inc', 'w') do |file|
file.puts"parameter FV(i) /"
#nannies = Nanny.all
#nannies.each do |nanny|
file.puts "#{nanny.name} #{nanny.fuehrerschein ? 1 : 0}"
end
end

Why isn't .replace working in Ruby Shoes?

I am programming a little game based on the Fate RPG. When the dice are rolled, I want to replace a string with another string using .replace. I can get it to work in an isolated environment, but when I try to call the function from inside my program; it is as if Shoes is completely unaware of it.
Here is a simple example of how the function works that is executing correctly:
Shoes.app {
#push = button "Push me"
#note = para "Nothing pushed so far"
#push.click { #note.replace "Aha! Click!" }
}
And here is the relevant code from my game:
$results = para "Roll results go here.", :align => "center",
:margin_bottom => 20, :margin_top => 8
#roll_button.click {
current_roll = Die.new
current_roll.roll
current_roll.display_dice
current_roll.tally
current_roll.calc_total_roll(1) #param = skill level
$shift = current_roll.calc_total_shift(2) #param = opposition
$results.replace "Actual results"
}
The $results block is in a different position in the code than the #roll_button.click block, but I have tries moving the click block to many different places in the code, and it didn't make a difference, so I don't think its relevant. Thanks.
*edit: Removed unnecessary '=' after $results.replace
I finally got it to work. The problem was the .display_dice function running just before .replace. The offending code is here:
if $result1 == 1
$die1.path = "dice_plus-1.png"
elsif $result1 == 0
$die1.path = "dice_nil-1.png"
elsif $result1 == -1
$die1.path = "dice_minus-1.png"
else
exit(1)
end
I intended the exit(1) to let me know if my dice were receiving values they shouldn't, but it somehow prevented the next line of code from running, even though the flow of the program avoided those lines. The fixed code is here:
if $result1 == 1
$die1.path = "dice_plus-1.png"
elsif $result1 == 0
$die1.path = "dice_nil-1.png"
else $result1 == -1
$die1.path = "dice_minus-1.png"
end
You're not calling a replace method, you're calling a replace= method which probably doesn't exist. Try it without the equals sign.

mysqli_real_escape_string correct syntax when using CASE for inserting to db

im having syntax errors thrown back at me when using mysqli_real_escape_string. The IDE that i am using shows no syntax issues, however this is the first time i have tried using this function with multiple CASE statements (infact i have not used this function very much at all).
The insertion code is here:
$query = "INSERT INTO `auctionwp_categories`
(`CategoryID`, `CategoryLevel`, `CategoryName`, `CategoryParentID`, `LeafCategory`, `AutoPayEnabled`, `BestOfferEnabled`, `Expired`, `IntlAutosFixedCat`, `Virtual`, `LSD`, `ORPA`)
VALUES (
'".mysqli_real_escape_string($link, $xmlCategoryID)."', '".mysqli_real_escape_string($link, $xmlCategoryLevel).", '".mysqli_real_escape_string($link, $xmlCategoryName).", '".mysqli_real_escape_string($link, $xmlCategoryParentID).",
CASE '".mysqli_real_escape_string($link, $xmlLeafCategory)."' WHEN 'true' THEN 1 ELSE 0 END,
CASE '".mysqli_real_escape_string($link, $xmlAutoPayEnabled)."' WHEN 'true' THEN 1 ELSE 0 END,
CASE '".mysqli_real_escape_string($link, $xmlExpired)."' WHEN 'true' THEN 1 ELSE 0 END,
CASE '".mysqli_real_escape_string($link, $xmlBestOfferEnabled)."' WHEN 'true' THEN 1 ELSE 0 END,
CASE '".mysqli_real_escape_string($link, $xmlIntlAutosFixedCat)."' WHEN 'true' THEN 1 ELSE 0 END,
CASE '".mysqli_real_escape_string($link, $xmlVirtual)."' WHEN 'true' THEN 1 ELSE 0 END,
CASE '".mysqli_real_escape_string($link, $xmlLSD)."' WHEN 'true' THEN 1 ELSE 0 END,
CASE '".mysqli_real_escape_string($link, $xmlORPA)."' WHEN 'true' THEN 1 ELSE 0 END
)";
if (mysqli_query($link, $query)) {
echo "Successfully inserted " . mysqli_affected_rows($link) . " row";
} else {
echo "Error occurred: " . mysqli_error($link);
}
Connection to db is successfull via this code in a config file:
$user="root";
$pass="";
$database="auctionwp";
$server="localhost";
$link = mysqli_connect($server, $user, $pass, $database);
if (!$link) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
echo 'Success... ' . mysqli_get_host_info($link) . "\n";
Is my problem of syntax due to the CASE statements? i can find no examples online or in php manual that show mysqli_real_escape_string being used on insertion with this statement,
regards
Martin
Thanks for your reply, before i had chance to see that someone had replied i managed to get it working keeping the CASE statements intact, it was actually quite easy once i got my head around it.
What i did was this:
// escape the returned values
$xmlCategoryName = mysqli_real_escape_string($link, $xmlCategoryName);
$xmlLeafCategory = mysqli_real_escape_string($link, $xmlLeafCategory);
$xmlBestOfferEnabled = mysqli_real_escape_string($link, $xmlBestOfferEnabled);
$xmlAutoPayEnabled = mysqli_real_escape_string($link, $xmlAutoPayEnabled);
$xmlExpired = mysqli_real_escape_string($link, $xmlExpired);
$xmlIntlAutosFixedCat = mysqli_real_escape_string($link, $xmlIntlAutosFixedCat);
$xmlVirtual = mysqli_real_escape_string($link, $xmlVirtual);
$xmlLSD = mysqli_real_escape_string($link, $xmllSD);
$xmlORPA = mysqli_real_escape_string($link, $xmlORPA);
// the insert query for the values
$query = "INSERT INTO `auctionwp_categories`
(`CategoryID`, `CategoryLevel`, `CategoryName`, `CategoryParentID`, `LeafCategory`, `AutoPayEnabled`, `BestOfferEnabled`, `Expired`, `IntlAutosFixedCat`, `Virtual`, `LSD`, `ORPA`)
VALUES (
'".$xmlCategoryID."', '".$xmlCategoryLevel."', '".$xmlCategoryName."', '".$xmlCategoryParentID."',
CASE '$xmlLeafCategory' WHEN 'true' THEN 1 ELSE 0 END,
CASE '$xmlAutoPayEnabled' WHEN 'true' THEN 1 ELSE 0 END,
CASE '$xmlExpired' WHEN 'true' THEN 1 ELSE 0 END,
CASE '$xmlBestOfferEnabled' WHEN 'true' THEN 1 ELSE 0 END,
CASE '$xmlIntlAutosFixedCat' WHEN 'true' THEN 1 ELSE 0 END,
CASE '$xmlVirtual' WHEN 'true' THEN 1 ELSE 0 END,
CASE '$xmlLSD' WHEN 'true' THEN 1 ELSE 0 END,
CASE '$xmlORPA' WHEN 'true' THEN 1 ELSE 0 END
)";
All seems to be working right now as required.
if i really had to, i'd still use a SQL IF operation which goes as follows:
IF [condition] THEN [statement] ELSE [statement] END IF
but since your working in php already why bother?! go for an if statement within php ;)
$query = "INSERT INTO `auctionwp_categories` (`CategoryID`, `CategoryLevel`, `CategoryName`, `CategoryParentID`, `LeafCategory`, `AutoPayEnabled`, `BestOfferEnabled`, `Expired`, `IntlAutosFixedCat`, `Virtual`, `LSD`, `ORPA`) VALUES (
'".mysqli_real_escape_string($link, $xmlCategoryID)."',
'".mysqli_real_escape_string($link, $xmlCategoryLevel).",
'".mysqli_real_escape_string($link, $xmlCategoryName).",
'".mysqli_real_escape_string($link, $xmlCategoryParentID).",
".mysqli_real_escape_string($link, $xmlLeafCategory) == 'true' ? 1 : 0.",
".mysqli_real_escape_string($link, $xmlAutoPayEnabled) == 'true' ? 1 : 0.",
".mysqli_real_escape_string($link, $xmlExpired) == 'true' ? 1 : 0.",
".mysqli_real_escape_string($link, $xmlBestOfferEnabled) == 'true' ? 1 : 0.",
".mysqli_real_escape_string($link, $xmlIntlAutosFixedCat) == 'true' ? 1 : 0.",
".mysqli_real_escape_string($link, $xmlVirtual) == 'true' ? 1 : 0.",
".mysqli_real_escape_string($link, $xmlLSD) == 'true' ? 1 : 0.",
".mysqli_real_escape_string($link, $xmlORPA) == 'true' ? 1 : 0."
)";

Resources