When I'm doing " sum(ev3.MT_BRUT) as Ecart " I lost all rows with ev3.MT_BRUT=.
My code is :
RECSET2.Open " select dossier.NO_POLICE, ev1.D_EFFET, ev1.ID_FAMILLE_PORTEF, ev1.ID_PORTEFEUILLE, gr.LB_COURT_GR_EVT, pers1.S_PRENOM||' '||pers1.S_NOM as Collaborateur, proto.CD_PROTOCOLE, ev1.ID_FAMILLE_PORTEF,comm.L_COMMENT_DOSSIER," & _
" dossier.UI_CREATION, ev1.LP_STATUT_EVT, sum(ev3.MT_BRUT) as Ecart, ev1.MT_BRUT, tiers2.CD_TIERS as Tmandataire, pers3.S_RAISONSOC as Mandataire,tiers1.CD_TIERS as Tdepositaire, pers2.S_RAISONSOC as Depositaire, ev1.IS_EVENEMENT from DB_DOSSIER dossier left join DB_EVENEMENT ev1 " & _
" on dossier.IS_DOSSIER = ev1.IS_DOSSIER left join DB_EVENEMENT ev2 on ev1.IS_EVENEMENT=ev2.IS_EVENEMENT_PERE left join DR_LIEN_EVT drevl on ev2.IS_EVENEMENT=drevl.IS_EVENEMENT left join DB_EVENEMENT ev3 on drevl.IS_EVT_LIE=ev3.IS_EVENEMENT left join DP_CLASSE_EVT cl on ev1.IS_CLASSE_EVT=cl.IS_CLASSE_EVT " & _
" left join DP_GROUPE_EVT gr on cl.IS_GR_EVT=gr.IS_GR_EVT left join DB_COMMENT_DOSSIER comm on dossier.IS_DOSSIER=comm.IS_DOSSIER left join DR_COLLABORATEUR_PROTOCOLE collabproto on dossier.IS_PROTOCOLE=collabproto.IS_PROTOCOLE left join DB_COLLABORATEUR collab on collabproto.IS_COLLABORATEUR=collab.IS_COLLABORATEUR " & _
" left join DB_PERSONNE pers1 on collab.IS_PERSONNE=pers1.IS_PERSONNE left join DB_PROTOCOLE proto on dossier.IS_PROTOCOLE=proto.IS_PROTOCOLE left join DB_PORTEFEUILLE portef1 on ev1.ID_FAMILLE_PORTEF=portef1.ID_FAMILLE_PORTEF and ev1.ID_PORTEFEUILLE=portef1.ID_PORTEFEUILLE left join DB_TIERS tiers1 on tiers1.IS_TIERS=portef1.IS_TIERS_DEPOSITAIRE " & _
" left join DB_PERSONNE pers2 on tiers1.IS_PERSONNE=pers2.IS_PERSONNE left join DB_TIERS tiers2 on tiers2.IS_TIERS=portef1.IS_TIERS_GESTIONNAIRE left join DB_PERSONNE pers3 on tiers2.IS_PERSONNE=pers3.IS_PERSONNE " & _
" where dossier.CD_DOSSIER in ('COROP','COROC') and dossier.LP_ETAT_DOSS not in ('CLOSE','ANNUL','A30') and ev1.D_EFFET>='" & Ma_date & "' and ev1.IS_EVENEMENT_PERE is null and drevl.LP_LIEN_EVT in ('COROP','COROC') " & _
" group by dossier.NO_POLICE, ev1.D_EFFET, ev1.ID_FAMILLE_PORTEF, ev1.ID_PORTEFEUILLE, gr.LB_COURT_GR_EVT, pers1.S_PRENOM, pers1.S_NOM, proto.CD_PROTOCOLE, ev1.ID_FAMILLE_PORTEF,comm.L_COMMENT_DOSSIER," & _
" dossier.UI_CREATION, ev1.LP_STATUT_EVT, ev1.MT_BRUT, tiers2.CD_TIERS, pers3.S_RAISONSOC,tiers1.CD_TIERS, pers2.S_RAISONSOC, ev1.IS_EVENEMENT ", cnn_Pegase, adOpenDynamic, adLockBatchOptimistic
I'm wondering if my export is working for the "Ecart" missing values :
xlRow = Range("Chapeau").Row + 1 + xlRow
If Not RECSET2.EOF Then
Do While Not RECSET2.EOF
ActiveSheet.Cells(xlRow, Range("Colonne_1").Column).Value = RECSET2("LB_COURT_GR_EVT").Value
ActiveSheet.Cells(xlRow, Range("Colonne_2").Column).Value = RECSET2("Collaborateur").Value
ActiveSheet.Cells(xlRow, Range("Colonne_3").Column).Value = RECSET2("CD_PROTOCOLE").Value
ActiveSheet.Cells(xlRow, Range("Colonne_4").Column).Value = RECSET2("NO_POLICE").Value
RECSET2.MoveNext
xlRow = xlRow + 1
Loop
Else
ActiveSheet.Cells(xlRow, Range("Colonne_1").Column).Value = ""
ActiveSheet.Cells(xlRow, Range("Colonne_2").Column).Value = ""
ActiveSheet.Cells(xlRow, Range("Colonne_3").Column).Value = ""
ActiveSheet.Cells(xlRow, Range("Colonne_4").Column).Value = ""
*****************************************************************
End If
RECSET2.Close
Call DECONNEXION_PEGASE
Thank your for help !
Related
#Let's start a coffee shop together!! We're going to build a coffee shop using some new Python programming concepts!!
#Let's build robot Barista!!
from time import sleep
print("\nHello! Welcome to Star Bucks.")
name = input("What is your name?\n")
print("Hello " + name + ", thank you so much for coming in today.\n")
sleep(2)
#To make it wait two seconds before showing the menu
menu = "Black Coffee, Espresso, Latte, Cappucino"
print (name + ", what would you like from our menu today? Here is what we are serving.\n" + menu)
order = input()
price = float(2.50)
quantity = input("How many " + order + "'s would you like?\n")
total = price * float(quantity)
print(format("Thank you. Your total of " + quantity + " " + order + " will be €" + str(total)))
print("\nSounds good " + name + ", we'll have your " + quantity + " " + order + "'s ready for you in a moment.")
You need to format the float like this "{:.2f}".format(total)
Your last line becomes:
print(format("Thank you. Your total of " + quantity + " " + order + " will be €" + "{:.2f}".format(total)))
I have a dataframe where i want to add an binary column indicator. The below is for shop e. I need to create many such flag columns depending on what the letter is e.g. shop e, a, b, c, d...
df = df[df['ope_p_e'] == 0]
df["shop_e_flag"] = np.where(((df['reven_a']==0)
& (df['reven_b']==0)
& (df['reven_c']==0)
& (df['reven_d']==0)
& (df['reven_f']==0))
& (df['reven_e'] >0) , 1, 0)
for shop b i need to do :
df = df[df['ope_p_b'] == 0]
df["shop_b_flag"] = np.where(((df['reven_a']==0)
& (df['reven_e']==0)
& (df['reven_c']==0)
& (df['reven_d']==0)
& (df['reven_f']==0))
& (df['reven_b'] >0) , 1, 0)
so each time the pre filter changes according to flag column i am creating. How can i automate the above..otherwise i end up writing the same code for each shop! Is there an easier way to automate this where i can 'select' the shop name i want flag for and it creates the above logic?
i tried the following but it takes so long:
def create_col(df,shop='a'):
all_shops = ['a','b','c','d','e']
other_shops = [x for x in all_shops if x not in shop]
df = df[df[f'ope_p_{shop}'] == 0]
df[f"shop_{shop}_flag"] = np.where(((df[f'reven_{other_shops[0]}']==0)
& (df[f'reven_{other_shops[1]}']==0)
& (df[f'reven_{other_shops[2]}']==0)
& (df[f'reven_{other_shops[3]}']==0)
& (df[f'reven_{other_shops[4]}']==0))
& (df[f'reven_{shop}'] >0) , 1, 0)
return df
How can i optimize this?
Question 1: I am not sure how to get first_name to display on lines 27-28. What code do I add?
Question 2: I want the input for lines 27-28 with the question "What type of Coffee would you like today?" to be bypassed using only the correct coffee types of ["Expresso", "Latte", "Cappuccino", "Mocha", "Frappuccino"] with a loop containing "break" to pass to next question and "continue" to retry if the user input did not choose from 1 or more coffee types and in which they can also include the word "and" and comma "," for correct input like "Expresso and Latte" or "Expresso Latte" or "Expresso, Latte and Mocha" or even "Expresso Latte Mocha", all which still allow comma's, "and" and 5 coffee type choices ONLY to bypass to the next question.
What code do I need to add?
Code
company_name = "Daniel's Coffee"
def greet():
print("\n" + "Hello" + "!" + " " + "Welcome to" + " " + company_name + "!" + "\n")
greet()
def name():
while True:
first_name = input("Can I start off with your first name?" + "\n\n")
if len(first_name) >= 3:
print("\n" + "Thank you," + " " + first_name.capitalize() + "!")
break
else:
print("\n" + "Invalid input," + " " + "please try again" + "!" + "\n")
continue
name()
def coffee_order():
while True:
order = input("\n" + first_name + "What type of Coffee would you like today?" +
"\n\n"
+ "\n".join(["Expresso", "Latte", "Cappuccino", "Mocha",
"Frappuccino"]) + "\n\n")
order = order.replace("and a", "")
order = order.replace("and", "")
order = order.replace(",", "")
order = order.lower().split()
union = " and a " if len(order) > 1 else ""
plural = "" if len(order) > 1 else ""
if order:
order = input("\n" + "You have selected a" + " " + ", ".join(order[:-1]).title()
+ union + plural +
order[-1].title() + "!" + " " + "\n\n" + "Is that correct?" +
"\n\n")
if order.capitalize() == "Yes":
print("\n" + "Wonderful" + "!")
break
elif order.capitalize() == "No":
continue
else:
print("Invalid input, please try again" + "!")
continue
coffee_order()
For the first name to be available you need to provide it as an argument to coffee_order or have a global variable defined outside and then accessed inside the function using global first_name before usage.
A much better approach would be to group these attributes and functions in a class. Below I have provided a template for this to help you experiment and use it for your project:
class CoffeeShop:
"""Coffee shop class."""
COFFEE_TYPES = ["Expresso", "Latte", "Cappuccino", "Mocha", "Frappuccino"]
def __init__(self):
self.company_name = "Daniel's Coffee"
self.first_name = None
def greet(self):
"""Print greeting."""
print(f"Hello! Welcome to {self.company_name}!")
def get_name(self):
"""Get customer first name."""
while True:
self.first_name = input("Can I start off with your first name?\n")
if len(self.first_name) >= 3:
print(f"Thank you {self.first_name}!")
return
print("You must enter at least 3 characters!\n")
def coffee_order(self):
"""Process coffee order."""
while True:
order = input(f"{self.first_name}, what coffee would you like today?\n "
f"Available coffee types are : {CoffeeShop.COFFEE_TYPES}\n")
if order in CoffeeShop.COFFEE_TYPES:
print(f"You have selected {order}. Thank you!")
return
print(f"{order} is not currently available.\n Please chose one of following: {CoffeeShop.COFFEE_TYPES}")
coffee_shop = CoffeeShop()
coffee_shop.greet()
coffee_shop.get_name()
coffee_shop.coffee_order()
i make a computed field char that get values as strings from fields but empty field get False as string , i need when any field equal False ignore it from computing ?
i tried to make a model_field as example if false do another compute method
#api.one
#api.depends('car','model','dsc','drc','year','org')
def _compute_amount(self):
for self in self:
if self.model.name:
self.model= False
self.name = str(str(self.car.name) + " " + str(self.dsc.name) + " " + str(self.drc.name) + " " + str(self.year.name)+" " +str(self.org.name))
else:
model=self.model
name = str(str(self.car.name) + " " + str(self.model.name) + " " + str(self.dsc.name) + " " + str(self.drc.name) + " " +str(self.org.name)+ " " +str(self.year.name))
the value of my code that all field be false when model_field is false
Your code is not even remotely close to what you should do to get your value, try learning Python basic for example looping and conditioning before you jump to code in a framework. Meanwhile, check following code, should serve your purpose
#api.multi
#api.depends('car','model','dsc','drc','year','org')
def _compute_amount(self):
name_fields = ('car','model','dsc','drc','year','org')
for record in self:
computed_name = ""
for field in name_fields:
field_value = getattr(record, field)
if field_value:
computed_name += field_value.name
record.name = computed_name
I am trying to automate some repetitive work for getting results from a website,
this link Drugs.com, checks for interaction between two medicines.
I must take the text of the two medicines from the Excel sheet and enter them on the website to check the interaction between them.
Here is a sample of my Excel sheet:
column(A) Column(B)
(A1)candesartan benazepril
(A2)eprosartan captopril
(A3)irbesartan enalapril
When I press 'Check For Interaction' the result of the next page must be extracted and return one of tree interactions:
-major
-moderate
-minor
This must then write the result to column(c)
I am a beginner at autoit but I can do some scripting albeit with a lot of bugs.
I will appreciate it if someone can correct/assist me with the bugs in my code. I will also appreciate it if someone can help me with the correct keywords so that I can Google for examples and solutions.
Thanks all.
#include <Excel.au3>
#include <IE.au3>
#include <File.au3>
Local $sWorkbook = "C:\Users\Aligaaly\Desktop\autoit\test\drugs.xlsx"
Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook)
$oWorkbook = _Excel_BookAttach($sWorkbook)
GLOBAL $oIE = _IECreate("https://www.drugs.com/drug_interactions.php")
Local $oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
$text_form1 = _IEGetObjById($oIE, "livesearch-interaction")
If StringLower($oInput.classname) == "input-button search-button" and _IEFormElementGetValue($oInput) Then ; it is an input
Global $oInput_btn = $oInput
EndIf
Next
WinActivate("[CLASS:XLMAIN]", "")
For $i = 1 To 5
Global $sResulta = _Excel_RangeRead($oWorkbook, Default, 'A' & $i & ':A' & $i,1 )
For $y = 1 To 5
Global $sResultb = _Excel_RangeRead($oWorkbook, Default, 'B' & $y & ':B' & $y,1 )
WinActivate("[CLASS:IEFrame]", "")
_IEFormElementSetValue($text_form1, $sResulta )
_IEAction ($oInput_btn, "click")
sleep(5000)
_IEFormElementSetValue($text_form1, $sResultb )
_IEAction ($oInput_btn, "click")
sleep(5000)
For $oInput In $oInputs
If StringLower($oInput.value) == "check for interactions" Then
Global $check_btn = $oInput
EndIf
Next
_IEAction ($check_btn, "click")
sleep(5000)
$oButtonsa = _IETagnameGetCollection($oIE, "span")
For $oButtonn in $oButtonsa
If $oButtonn.classname == "status-category status-category-major" Then
WinActivate("[CLASS:XLMAIN]", "")
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "major","C" & $y)
ElseIf $oButtonn.classname == "status-category status-category-moderate" Then
WinActivate("[CLASS:XLMAIN]", "")
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "moderate","C" & $y)
ElseIf $oButtonn.classname == "status-category status-category-minor" Then
WinActivate("[CLASS:XLMAIN]", "")
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "minor","C" & $y)
EndIf
ExitLoop
Next
Next
Next
i have updated the code with my final touches
i think this code is now complete the steps i have write down above
but i have an error when the script finish the first iteration
The problem is in _IEFormElementSetValue function.
Probably,
$text_form1 = _IEGetObjById($oIE, "livesearch-interaction")
can't find any object.
For debug it you can insert this code before _IEFormElementSetValue:
ConsoleWrite("isObject:" & isObj($text_form1) & #CRLF)
Update: I found 3 problems.
1) You didn't return to search page after end of iteration and the input object can't be found;
2) You must get Input and Button object on the start of each iteration;
3) Exitloop must be on each If ... esleif section.
Try this code:
#include <Excel.au3>
#include <IE.au3>
#include <File.au3>
Local $sWorkbook = "C:\Users\Aligaaly\Desktop\autoit\test\drugs.xlsx"
Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook)
$oWorkbook = _Excel_BookAttach($sWorkbook)
GLOBAL $oIE = _IECreate("https://www.drugs.com/drug_interactions.php")
Local $oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
$text_form1 = _IEGetObjById($oIE, "livesearch-interaction")
If StringLower($oInput.classname) == "input-button search-button" and _IEFormElementGetValue($oInput) Then ; it is an input
Global $oInput_btn = $oInput
EndIf
Next
WinActivate("[CLASS:XLMAIN]", "")
For $i = 1 To 5
Global $sResulta = _Excel_RangeRead($oWorkbook, Default, 'A' & $i & ':A' & $i,1 )
For $y = 1 To 5
Global $sResultb = _Excel_RangeRead($oWorkbook, Default, 'B' & $y & ':B' & $y,1 )
$oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
$text_form1 = _IEGetObjById($oIE, "livesearch-interaction")
If StringLower($oInput.classname) == "input-button search-button" and _IEFormElementGetValue($oInput) Then ; it is an input
$oInput_btn = $oInput
EndIf
Next
WinActivate("[CLASS:IEFrame]", "")
_IEFormElementSetValue($text_form1, $sResulta )
_IEAction ($oInput_btn, "click")
sleep(5000)
_IEFormElementSetValue($text_form1, $sResultb )
_IEAction ($oInput_btn, "click")
sleep(5000)
For $oInput In $oInputs
If StringLower($oInput.value) == "check for interactions" Then
Global $check_btn = $oInput
EndIf
Next
_IEAction ($check_btn, "click")
sleep(5000)
$oButtonsa = _IETagnameGetCollection($oIE, "span")
For $oButtonn in $oButtonsa
If $oButtonn.classname == "status-category status-category-major" Then
WinActivate("[CLASS:XLMAIN]", "")
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "major","C" & $y)
ExitLoop
ElseIf $oButtonn.classname == "status-category status-category-moderate" Then
WinActivate("[CLASS:XLMAIN]", "")
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "moderate","C" & $y)
ExitLoop
ElseIf $oButtonn.classname == "status-category status-category-minor" Then
WinActivate("[CLASS:XLMAIN]", "")
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "minor","C" & $y)
ExitLoop
EndIf
Next
_IENavigate($oIE, "https://www.drugs.com/drug_interactions.php?action=new_list")
Next
Next