How to use FILTERS in MessageHandler from a list of values - filter

I just started learning Python and Telegram Bot and I cannot find the way to menage the reply for values included in a list.
I have create a keyboard with 4 buttons with customers from #1 to #4
I want that when the user press either on Customer1 or Customer2 function abs is exectuded, otherwise if he press on Customer 3 and 4 function 3 and 4 is exectuded
list1 = ["customer1", "customer2"]
list2 = ["customer3", "customer4"]
updater.dispatcher.add_handler(MessageHandler(Filters.regex(r"customer1"), abc))
updater.dispatcher.add_handler(MessageHandler(Filters.regex(r"customer2"), abc))
updater.dispatcher.add_handler(MessageHandler(Filters.regex(r"customer3"), def))
updater.dispatcher.add_handler(MessageHandler(Filters.regex(r"customer4"), def))
Thanks to anyone who could help me!! :-)

Related

Prolog sudoku error, returns false no matter what

I have probelm with this:
:-use_module(library(clpfd)).
sudoku(R) :-
length(R,9), /*red je duzine 9*/
maplist(same_length(R),R), /*svi redovi su iste duzine*/
append(R,E), /*elemente svih redova gurnem u jednu listu*/
E ins 1..9, /* svi elementi te liste su veci od 1 i manji od 9*/
maplist(all_distinct,R), /*svi elementi po redovimasu medjusobno razliciti*/
transpose(R,C), /*rotira matricu 90 stepeni u desno i time kolone postaju redovi*/
maplist(all_distinct, C),
R = [A,B,C,D,E,F,G,H,I], /*svaki red dobije ime*/
kvadratic(A,B,C), /* predkat kvadratic ce se pobrinuti da*/
kvadratic(D,E,F), /* kvadrati 3 x 3 unutar matrice takodje*/
kvadratic(G,H,I). /* sadrze medjusobno razlicite elemente*/
kvadratic([],[],[]). /* ako smo dosli do praznih lista stane */
kvadratic([E1,E2,E3|T1],[E4,E5,E6|T2],[E7,E8,E9|T3]) :-
all_distinct([E1,E2,E3,E4,E5,E6,E7,E8,E9]),
kvadratic(T1,T2,T3). /* pozovemo za ostatak listi */
As you can see this is my code (with some comments, which is same as one on swi prolog website), and when i run it i get just "false". Can someone please help me? Thanks!
So, as I expected, problem is something really stupid. In predicate sudoku i used letters C and E for 2 totally different things (they were not the same thing, just 2 separate variables were named by same letter by me). After changing that program works perfectly!

Find mutual element in different facts in swi-prolog

i am trying to have an input of a list of movies and find the actors who play at the same movies.
Question : Given a list of movies, display their link by a set of stars using recursion.
these are an example of facts :
fact(movie,actor).
starsin(a,bob).
starsin(b,bob).
starsin(c,bob).
starsin(a,maria).
starsin(b,maria).
starsin(c,maria).
starsin(a,george).
starsin(b,george).
starsin(c,george).
Example of input and out put :
?- sameActors([a,b,c],Y).
Y = bob,maria,george.
Rule written so far :
sameActors(Actors,Movies) :-
findall(Stars,(member(movie,Actors),starsin(movie,Stars)),Name),
sum_list(Name,Movies).
I am quite new and can't find any similar solution online for my problem, i don't understand what i am doing wrong , or what i need to add.
Here is another one (I finally found a way)
No recursion, just a relative of findall, setof/3:
Given a database of "actors starring in movies":
starsin(a,bob).
starsin(c,bob).
starsin(a,maria).
starsin(b,maria).
starsin(c,maria).
starsin(a,george).
starsin(b,george).
starsin(c,george).
starsin(d,george).
We do some reflection (described in setof/3 inside setof/3 not working, but why?), and then:
subselect(Ax,MovIn) :-
setof(Mx,starsin(Mx,Ax),MovAx), subset(MovIn, MovAx).
actors_appearing_in_movies(MovIn,ActOut) :-
setof(Ax, subselect(Ax,MovIn) , ActOut).
This has the right feel of being an RDBMS operation!
Testing!
Note that for the empty set of movies, we get all the actors. This is marginally right: all the actors
star in all the movies of the empty set.
Testing consists in running these goals and observing that they succeed:
actors_appearing_in_movies([],ActOut),
permutation([bob, george, maria],ActOut),!.
actors_appearing_in_movies([a],ActOut),
permutation([bob, george, maria],ActOut),!.
actors_appearing_in_movies([a,b],ActOut),
permutation([george, maria],ActOut),!.
actors_appearing_in_movies([a,b,c],ActOut),
permutation([george, maria],ActOut),!.
actors_appearing_in_movies([a,b,c,d],ActOut),
permutation([george],ActOut),!.
Bonus Round: In R
Completely unrelated, but I thought about how to do that in R.
After some fumbling:
# Load tidyverse dplyr
library(dplyr)
# Create a data frame ("tibble") with our raw data using `tribble`
t <- tribble(
~movie, ~actor
,"a" , "bob"
,"c" , "bob"
,"a" , "maria"
,"b" , "maria"
,"c" , "maria"
,"a" , "george"
,"b" , "george"
,"c" , "george"
,"d" , "george")
# The function!
actors_appearing_in_movies <- function(data, movies_must) {
# (movie,actor) pairs of actors active in movies we are interested in
t1 <- data %>% filter(is.element(movie, movies_must))
# (actor, (movies)) pairs of actors and the movies they appear in
# for movies we are interested in
t2 <- t1 %>% group_by(actor) %>% summarize(movies = list(unique(movie)))
# Retain only those which appear in all movies
t3 <- t2 %>% rowwise() %>% filter(setequal(movies_must,movies))
# Select only the actor column
# ("Select" works columnwise, not rowwise as in SQL)
t4 <- t3 %>% select(actor)
return(t4)
}
Results?
The above approach has a different opinion on who is in the empty movie set:
> actors_appearing_in_movies(t, c())
# A tibble: 0 x 1
# … with 1 variable: actor <chr>
But:
> actors_appearing_in_movies(t, c("a"))
# A tibble: 3 x 1
actor
<chr>
1 bob
2 george
3 maria
> actors_appearing_in_movies(t, c("a","b"))
# A tibble: 2 x 1
actor
<chr>
1 george
2 maria
> actors_appearing_in_movies(t, c("a","b","c"))
# A tibble: 2 x 1
actor
<chr>
1 george
2 maria
> actors_appearing_in_movies(t, c("a","b","c","d"))
# A tibble: 1 x 1
actor
<chr>
1 george

U2 Universe Update Multi value field errror

I am using the Universe U2.net toolkit to update the record in universe database. We have so far no issue with update to non multi value field with the following code
Open_Again:
Try
db_connectionU2 = openConnU2()
db_connectionU2.Open()
Catch ex As Exception
GoTo Open_Again
End Try
Dim cmdWIP As New U2Command
'cmdWIP = New U2Command("DELETE FROM MPS", db_connectionU2)
cmdWIP = New U2Command("UPDATE POH SET EPOS=#FLAG where PONO='C11447'", db_connectionU2)
cmdWIP = New U2Command("UPDATE CURCVRD F8=#F8 where F0='51747*1'", db_connectionU2)
cmdWIP.Parameters.Add(New U2Parameter("#F8", U2Type.VarChar)).Value = "t"
cmdWIP.Connection = db_connectionU2
cmdWIP.ExecuteNonQuery()
cmdWIP.Dispose()
cmdWIP = Nothing
db_connectionU2.Close()
db_connectionU2.Dispose()
db_connectionU2 = Nothing
but it having the problem when we try to add in to multivalue field. It's return the error " Column being update from single to multi is illegal. Please see the red box for the message and the value we are writing in.
Please click below to see the screenshot
enter image description here
Thank you
You need to look at the DICT of that file and make sure your entries are marked and MultiValued and have an Multi-Value Association.
Here is an example from the HS.SALES demo account.
>LIST DICT CUSTOMER
DICT CUSTOMER 03:56:47pm 01 Dec 2016 Page 1
Type &
Field......... Field. Field........ Conversion.. Column......... Output Depth &
Name.......... Number Definition... Code........ Heading........ Format Assoc..
CUSTID D 0 P(0N) Customer ID 10R S
#ID D 0 CUSTOMER 10L S
SAL D 1 Salutation 5T S
FNAME D 2 First Name 12T S
LNAME D 3 Last Name 16T S
COMPANY D 4 Company Name 20T S
ADDR1 D 5 Address line 1 30T S
ADDR2 D 6 Address line 2 30T S
CITY D 7 City 12T S
STATE D 8 P(2A) State 2L S
MCU
ZIP D 9 P(5N) Zip 5L S
PHONE D 10 P("("3N")"3N Telephone 13R S
-4N)
PRODID D 11 P(1A4N) Product 5L M ORDER
S
SER_NUM D 12 P(6N) Serial# 6L M ORDER
S
Notice how PRODID has "M ORDERS" after is (the is drops to the next line thanks to the 80 char size of my terminal. This tells Universe that it is a multivalued field with an Association called ORDERS. This allows the SQL interpreter to know how to update things.
It gets a bit more complicated and I would recommend looking up HS.ADMIN and specifically HS.SCRIB for tips on formatting things for non-pick style consumption. Check the UVodbc guide for more info on that.

Rename Finder Items

I am looking to create a script and was wanting to know if this is something that is possible. I have a little knowledge of applescript. But this one is confusing me.
I have a list of loose files inside of one folder that reads as such.
1111111111 010
1111111111 011
1111111222 012
1111111222 013
1111111222 014
1111111243 020
1111111243 021
Its very random every time. But there is always a 10 digit number that is constant, but I would like to add a sequential number starting with one that resets every time the number changes. So that the file name would look like this.
1111111111_1
1111111111_2
1111111222_1
1111111222_2
1111111222_3
1111111243_1
1111111243_2
Any help is much appreciated. Thanks.
tell application "Finder"
set prev to missing value
repeat with f in (get files of (POSIX file "/Users/username/folder" as alias))
set w1 to word 1 of (get name of f)
if w1 is prev then
set n to n + 1
else
set n to 1
end if
set name of f to w1 & "_" & n
set prev to w1
end repeat
end tell
You could also run a command like this in Terminal:
cd ~/folder;for f in *;do w1=${f% *};[ $prev = $w1 ]&&let n++||n=1;mv "$f" $w1\_$n;prev=$w1;done

how to calculate correlation with a sliding window?

I have a zoo object called aux with yearly data from 1961 to 2009:
x$nao x[, 2]
1961 -0.03 63.3
1962 0.20 155.9
1963 -2.98 211.0
I want to calculate the correlation between the two columns using a 20 years sliding window. I am trying to use rollapply, but I don't seem to be able to make it work. I tried several different ways of doing it but always without success...
> rollapply(aux,20, cor(aux[,1],aux[,2],method="pearson"))
Error in match.fun(FUN) : 'cor(aux[, 1], aux[, 2], method = "pearson")' is not a function, character or symbol
> rollapply(aux,20, cor,method="pearson")
Error in FUN(coredata(data)[posns], ...) : supply both 'x' and 'y' or a matrix-like 'x'
> rollapply(aux,20, cor)
Error in FUN(coredata(data)[posns], ...) : supply both 'x' and 'y' or a matrix-like 'x'
Can anybody tell me how to make rollapply work?
Thanks for helping!
Try this.
library(quantmod)
library(TTR)
#Set the seed so results can be duplicated
set.seed(123)
#Build a zoo object with typical price data
var1 <- zoo(cumprod(1+rnorm(50, 0.01, 0.05)), seq(1961, 2001, 1))
var2 <- zoo(cumprod(1+rnorm(50, 0.015, 0.1)), seq(1961, 2001, 1))
dat <- merge(var1=var1, var2=var2)
plot(dat)
grid()
#Calculate the percent returns for the two prices
del1 <- Delt(dat$var1)
del2 <- Delt(dat$var2)
dat <- merge(dat, del1=del1, del2=del2)
dimnames(dat)[[2]][3] <- "del1"
dimnames(dat)[[2]][4] <- "del2"
head(dat)
plot(dat)
#Calculate the correlation between the two returns using a 5 year sliding window
delcor <- runCor(dat$del1, dat$del2, n=5, use="all.obs", sample=TRUE, cumulative=FALSE)
dat <- merge(dat, delcor)
plot(dat$delcor, type="l", main="Sliding Window Correlation of Two Return Series", xlab="", col="red")
grid()

Resources