I am trying to make automatic attendance on my android phone [which is triggered by NFC]. I have tested the following Python code separately on PC:
from datetime import datetime
s1 = '09:40:00'
s2 = datetime.now().strftime('%H:%M:%S')
s3 = datetime.now().strftime('%I:%M:%S %p')
FMT = '%H:%M:%S'
tdelta = datetime.strptime(s2, FMT) - datetime.strptime(s1, FMT)
print ('I have arrived ['+str(tdelta)+']' 'HH:MM:SS'' late at ['+str(s3)+'].')
And following Android Code separately:
droid = android.Android
import android
number = "mycellnumber"
message = "Hello"
droid.smsSend(number, message.encode("utf-8"))
What I want is to merge these two codes and send the following as message(and in email body later):
('I have arrived ['+str(tdelta)+']' 'HH:MM:SS'' late at ['+str(s3)+'].')
I am able to merge the code and now it looks like this:
import android
import datetime
droid = android.Android()
s1= '09:40:00'
s2= datetime.datetime.now().strftime('%H:%M:%S')
s3= datetime.datetime.now().strftime('%I:%M:%S %p')
FMT = '%H:%M:%S'
tdelta = datetime.datetime.strptime(s2,FMT) - datetime.datetime.strptime(s1,FMT)
print ('I have arrived ['+str(tdelta)+']')
number = "XXXXXXXXXX"
message = str(tdelta)
droid.smsSend(number, message.encode("utf"))
Related
I'm using Xamarin forms in my android app I'm getting the datetime that I converted to
Egypt time but some devices read it nulls or countries I don't know the reason really but some others read it?
and that is my code
DateTime date = DateTime.Now;
var test = TimeZoneInfo.ConvertTime(date, TimeZoneInfo.FindSystemTimeZoneById("Africa/Cairo"));
It might help you
DateTime now = DateTime.UtcNow;
TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Africa/Cairo Standard Time");
TimeSpan utcOffset = timeZoneInfo.GetUtcOffset(now);
DateTime cairoTime = new DateTime(now.Ticks + utcOffset.Ticks, DateTimeKind.Local);
I'm pretty new to kotlin and would like to know how to format a number with commas.
Currently, my textview shows a number without any commas, i.e, 15000.
I want it to show 15,000 instead.
Here's my code that I want to format:
txtTotalActive.text = it.statewise[0].active
"it.statewise[0].active" is an object that shows number but as I said, it shows without any commas.
Solution:
var inoutValue = it.statewise[0].active
val number = java.lang.Double.valueOf(inoutValue)
val dec = DecimalFormat("#,###,###")
val finalOutput = dec.format(number)
txtTotalActive.text = finalOutput
"%,.2f".format(text.toFloat()) <,> = grouping , 2 = precision/number of decimals after "."
I am using Object detection api to train on my custom data for a 2 class problem.
I am using SSD Mobilenet v2. I am converting the model to TF lite and I am trying to execute it on python interpreter.
The value of score and class is somewhat confusing for me and I am unable to make a valid justification for the same. I am getting the following values for score.
[[ 0.9998122 0.2795332 0.7827836 1.8154384 -1.1171713 0.152002
-0.90076405 1.6943774 -1.1098632 0.6275915 ]]
I am getting the following values for class:
[[ 0. 1.742706 0.5762139 -0.23641224 -2.1639721 -0.6644413
-0.60925585 0.5485272 -0.9775026 1.4633082 ]]
How can I get a score of greater than 1 or less than 0 for e.g. -1.1098632 or 1.6943774.
Also the classes should be integers ideally 1 or 2 as it is a 2 class object detection problem
I am using the following code
import numpy as np
import tensorflow as tf
import cv2
# Load TFLite model and allocate tensors.
interpreter = tf.contrib.lite.Interpreter(model_path="C://Users//Admin//Downloads//tflitenew//detect.tflite")
interpreter.allocate_tensors()
# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
print(input_details)
print(output_details)
input_shape = input_details[0]['shape']
print(input_shape)
# change the following line to feed into your own data.
#input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)
input_data = cv2.imread("C:/Users/Admin/Pictures/fire2.jpg")
#input_data = cv2.imread("C:/Users/Admin/Pictures/images4.jpg")
#input_data = cv2.imread("C:\\Users\\Admin\\Downloads\\FlareModels\\lessimages\\video5_image_178.jpg")
input_data = cv2.resize(input_data, (300, 300))
input_data = np.expand_dims(input_data, axis=0)
input_data = (2.0 / 255.0) * input_data - 1.0
input_data=input_data.astype(np.float32)
interpreter.reset_all_variables()
interpreter.set_tensor(input_details[0]['index'], input_data)
interpreter.invoke()
output_data_scores = []
output_data_scores = interpreter.get_tensor(output_details[2]['index'])
print(output_data_scores)
output_data_class = []
output_data_class = interpreter.get_tensor(output_details[1]['index'])
print(output_data_class)
Looks like the problem is caused by the wrong input image channel order. Opencv imread reads images in 'BGR' format. You can try adding
input_data = cv2.cvtColor(input_data, cv2.COLOR_BGR2RGB)
to get a 'RGB' format image and then see if the result is reasonable.
Reference: ref
The output of tflite model requires post-processing. The model returns a fixed number (here, 10 detections) by default. Use the output tensor at index 3 to get the number of valid boxes, num_det. (i.e. top num_det detections are valid, ignore the rest)
num_det = int(interpreter.get_tensor(output_details[3]['index']))
boxes = interpreter.get_tensor(output_details[0]['index'])[0][:num_det]
classes = interpreter.get_tensor(output_details[1]['index'])[0][:num_det]
scores = interpreter.get_tensor(output_details[2]['index'])[0][:num_det]
Next, the box coordinates need to be scaled to the image size and adjusted so that the box is within the image (some visualization APIs require this).
df = pd.DataFrame(boxes)
df['ymin'] = df[0].apply(lambda y: max(1,(y*img_height)))
df['xmin'] = df[1].apply(lambda x: max(1,(x*img_width)))
df['ymax'] = df[2].apply(lambda y: min(img_height,(y*img_height)))
df['xmax'] = df[3].apply(lambda x: min(img_width,(x * img_width)))
boxes_scaled = df[['ymin', 'xmin', 'ymax', 'xmax']].to_numpy()
Here's a link to an inference script with input preprocessing, output post-processing and mAP evaluation.
The code is supposed to display a animated image walking in front of a background. I received this code from my professor and I'm not sure what the issue is.
import sys, os, math
sys.path.append("./")
from livewires import games
import spriteUtils
from spriteUtils import *
filename = sys.argv[1]
x = int(sys.argv[2])
y = int(sys.argv[3])
##print(filename, "\t", x, "\t", y)
games.init(screen_width = 1152, screen_height = 864, fps = 50)
nebula_image = games.load_image(os.path.join('.', "race_track.jpg"), transparent = 0)
games.screen.background = nebula_image
anim_list = load_2d_sheets(x, y, filename)
anim = games.Animation(images = anim_list,
x = games.screen.width/2,
y = 2*games.screen.height/4,
n_repeats = 15,
repeat_interval = 10)
games.screen.add(anim)
games.screen.mainloop()
I'd first print sys.argv so that you can see what it represents. For example:
$ ./myscript.py
>>> sys.argv
['/myscript.py']
>>> sys.argv[1]
IndexError
You probably want to pass additional command line arguments to your function like:
$ ./myscript.py firstvar secondvar
sys.argv[1] is the first argument that you pass to your script, so you need to run your script like this:
python my_script.py arg1
sys.argv[0] is the name of your script itself, in this example my_script.py
Looks like this script requires 3 arguments, and you aren't giving it any. The syntax for calling it on the command line is python script_name.py <file_name> <x> <y> where script_name.py is the name of the actual program, <file_name> is a string, and <x> and <y> are integers.
Mafia game helper is very simple. It allows me to input the number of roles(mafia, detective, innocents etc.) first. Then each player will input their name and the computer will randomly choose a role for him/her. And the first player pass the computer to the next player and so on. At the end, computer will generate a list.
Something like:
Tom : Mafia
John : detective
Here is my code:
import random
role=[]
k = input("Number of mafia: ")
p = input("Number of detective: ")
n = input("Number of innocent: ")
---magic---
random.shuffle(role)
player = []
i=0
while True:
name = raw_input()
player.append(name)
print role[i]
i += 1
I have two problems in programming this.
How can I make a list called 'role' with k 'mafia' , and p 'detective'? For example: if k = 3, p = 1, n = 1, then the list 'role' will be ['mafia', 'mafia', 'mafia', 'detective', 'innocent']. I know that I can do it with for loop but is there any easy way (a.k.a magic) to do this?
There is a very serious bug as now the second player can see what role is assigned to the first player. How can I solve this and make no player could see this? But I have to keep the results since I have to make a list at the end as I mentioned.
My friends love to play this game so much so I want to surprise them by this program!
Thank you for everyone read this. Have a good day =]
Regarding your list generation problem
>>> k = 3
>>> p = 1
>>> n = 2
>>> roles = ['mafia']*k + ['detective']*p + ['innocent']*n
>>> roles
['mafia', 'mafia', 'mafia', 'detective', 'innocent', 'innocent']
One method to randomly assign roles
from random import shuffle
shuffle(roles)
names = ['bob', 'steve', 'tom', 'jon', 'alex', 'mike']
players = dict(zip(names,roles))
>>> players
{'mike': 'innocent',
'alex': 'mafia',
'steve': 'mafia',
'tom': 'mafia',
'bob': 'detective',
'jon': 'innocent'}
You could clear the output after assigning each person? this should now clear
import random
import os
k = input("Number of mafia: ")
p = input("Number of detective: ")
n = input("Number of innocent: ")
roles = ['mafia']*k + p*['detective'] + n * ['innocent']
random.shuffle(roles)
while roles:
print 'name:',
name = raw_input()
print 'you are a ' + roles.pop(0)
print 'clear?'
clear = raw_input()
os.system('cls' if os.name == 'nt' else 'clear')
or alternatively you could write the roles out to individual files which might work better
import random
import os
k = input("Number of mafia: ")
p = input("Number of detective: ")
n = input("Number of innocent: ")
roles = ['mafia']*k + p*['detective'] + n * ['innocent']
random.shuffle(roles)
people = []
path = ''
while roles:
print 'name:',
name = raw_input()
while name in people:
print 'name already_taken please take new name'
name = raw_input()
people.append(name)
person_file = open(os.path.join(path,'%s.txt') % (name,),'w')
person_file.write('you are a %s' % (roles.pop(0),))
person_file.close()