lundi 1 juin 2020

moving average that changes over time

how could someone help me? I'm trying to make an indicator that has 2 moving averages, but when changing the timeframe of the chart, the periods of the moving averages also change. example: in the time of 1 hour it shows me 2 SMA of 10 and 20 and when changing to the daily chart it shows me 2 SMA of 30 and 60. thanks

t-sql loop through all rows and sum amount from column until value is reached

I have a table containing the below test data:

A table with userId, Name, Email and Amount of persons a table in restaurant is reserved for

I now would like to fill a restaurant with 12 seating spaces.

This should result in:

table result after selection

Basically, I need to loop from top to bottom through all rows and add the AmountPersons until I have filled the restaurant.

In this example:

(first few rows: AmountPersons) 3+1+2+4 = 10

UserId 52 can't be added because they reserved for 3 persons, which would result in 13 occupied places and there are only 12 available.

In the next row it notices a reservation for 1. This can be added to the previous 10 we already found.

NewTotal is now 11.

UserId 79 and 82 can't be added because we'd exceed the capacity again.

UserId 95 reserved for 1, this one can be added and we now have all places filled.

This is the result I get from the cursor I use, but I'm stuck now. Please help.

Temp_Result_Cursor

The while loop I have in the cursor basically stops when the next value would be higher than 12. But that is not correct.

Type of data in an F statement [closed]

I am a total newbie in Python. Could you help out with the following code?

ID_number = int(input("Write your ID_number: "))    
if str(ID_number[9]) %2 ==1:
 print("male")
else:
 print("female")

I suspect the problem may lie in this line, where I am not sure of correct type of data: string or integer

if str(ID_number[9]) %2 ==1:

I get an error "'int' object is not subscriptable". I searched for a possible problem on this website and many others, but still cannot find my error.

Thank you

Excel: IF statement with date range plus more

I'm learning to use formulas in excel I need your help with this IF statement.

https://drive.google.com/file/d/100EMdVteAgJO-ilDz8QNgtFEWWrBtqKb/view?usp=sharing

So when you see the sheet, I want to type in the data on the "Item" sheet and have it automatically added into the "Year" sheet. I want it so it looks up the date, category then adds the cost into its category on the "Year" sheet.

I played around with some IF(AND) formulas but nothing seemed to work.

Can anyone help with the formula?

Thank you

Parse a log file unformatted into a json file using dictionary in python

I have a log file and want to create a JSON out of it. The log file does not have specific format or patterns. So i should be able to use regex to split the key:value pairs. I have been trying to use if-elif conditions and also dictionary. It will be of great help if I could get a solution to develop this.

Using Luhn's module I am having a problem with IF statements

import luhn
from luhn import *

#BIN Must Be 6-Digits Long.
def gen():
  BIN = input("Enter A BIN Number: ")
  output = []
  for number in BIN:
    output.append(number)
  output = [int(num) for num in output]
  return (output)
BIN = gen()
if BIN <6 and len(BIN) is not 8:
    print('Invalid BIN!')
else:
    print('BIN Added To Directory!')


gen()

Specifically in the 'if' part my intention is that the 'BIN' which should be an integer is less than or greater than 6 print 'invalid' else print 'added to directory'. In addition, overall what Im looking for is if the BIN is not 6 digits long or greater than 6 digits long print 'error'.

dimanche 31 mai 2020

How to compare the variable which can be existed or null in MYSQL? [duplicate]

I am encountering an issue which is how to do comparison in where clause with the variable can be existed or null. I know there is a operator <=> can do that. But any other method can achieve the same result as <=>. My sample sp is as below. You can imagine I have a model for storing the number of fruit in each store. But the store name can be null which stands for the warehouse. So, the a_store_name can be really a store name or null, simply use = will throw error where there is comparing with null.

Sp:

CREATE PROCEDURE `sp_check_fruit`(IN a_store_name varchar(20))
sp:BEGIN
select fruit number
into number
from fruit
where store_name = a_store_name;
END