I need a stratified random sample that consists in a determined number of addresses. My stratification variable is the zip code.
The sample size is already pre-determined and has different number of observations per zip code. How can I incorporate the desired number ob observations per zip code? Is it possible to do this with PROC SURVEYSELECT? I have the sample size in an external file.
Example:
ZIP CODE NUMBER_OBSERVATIONS
9999 10
8888 15
7777 10
6666 5
Is it possible? How can I do this?
Thanks
Use the sampsize option and specify your dataset. It will limit all of the samples to each size of the strata.
proc surveyselect data = have
out = want
sampsize=external
;
strata zip;
size number_observations;
run;
Related
I have a ESP32, programmed using Arduino IDE.
In my code I have 2 variables: sName (string) and nScore (double).
This pair of variables, needs to be written to the EEPROM into the higscore namespace. So far it would be easy, open the namespace, and write the values..
but here comes the tricky part: The namespace highscore has 20 values: 10 names and 10 scores. I need to write the value to the namespace only if it is higher than those already present, and to add it to the correct spot in the high score table, shifting all the other values.
How should I do this?
Currently I am thinking of loading all the values on startup and storing it in 2 arrays. Then whenever something is changed in the array, write it down.
But I am not sure that this is the proper way of doing this.
Assuming that you want to minimize the number of writes to EEPROM,
the best way would be to assign 10 addresses of EEPROM, one for each highscore holder, and then have a separate variable in EEPROM to denote the order of the highscores.
eg:
ADD1: NameA
ADD2: NameB
ADD3: NameC
....
and then an
int ord = 231
Which would mean
1.NameC
2.NameA
3.NameB....
This way if someone new comes into the Scoreboard, rewrite only the address of the player with least score (eg: order 3 -> NameB) and rearrange the ord variable.
Since you have have 10 entries, your ord variable could be something like 7562931048, where 0 would be the highest scorer.
In any case you'll surely have to load all the scores(maybe just the numbers) into ram while startup(or at a later time) to compare.
Title may be wildly incorrect for what I'm trying to work out.
I'm trying to interpret packets I am recieving from a racing game in a way that I understand, but I honestly don't really know what I'm looking at, or what to search to understand it.
Information on the packets I am recieving here:
https://forums.codemasters.com/topic/54423-f1%C2%AE-2020-udp-specification/?tab=comments#comment-532560
I'm using python to print the packets, here's a snippet of the output, which I don't understand how to interpret.
received message: b'\xe4\x07\x01\x03\x01\x07O\x90.\xea\xc2!7\x16\xa5\xbb\x02C\xda\n\x00\x00\x00\xff\x01\x00\x03:\x00\x00\x00 A\x00\x00\xdcB\xb5+\xc1#\xc82\xcc\x10\t\x00\xd9\x00\x00\x00\x00\x00\x12\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00$tJ\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01
I'm very new to coding, and not sure what my next step is, so a nudge in the right direction will help loads, thanks.
This is the python code:
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 20777
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(4096)
print ("received message:", data)
The website you link to is describing the data format. All data represented as a series of 1's and 0's. A byte is a series of 8 1's and 0's. However, just because you have a series of bytes doesn't mean you know how to interpret them. Do they represent a character? An integer? Can that integer be negative? All of that is defined by whoever crafted the data in the first place.
The type descriptions you see at the top are telling you how to actually interpret that series of 1's and 0's. When you see "unit8", that is an "unsigned integer that is 8 bits (1 byte) long". In other words, a positive number between 0 and 255. An "int8" on the other hand is an "8-bit integer", or a number that can be positive or negative (so the range is -128 to 127). The same basic idea applies to the *16 and *64 variants, just with 16 bits or 64 bits. A float represent a floating point number (a number with a fractional part, such as 1.2345), generally 4 bytes long. Additionally, you need to know the order to interpret the bytes within a word (left-to-right or right-to-left). This is referred to as the endianness, and every computer architecture has a native endianness (big-endian or little-endian).
Given all of that, you can interpret the PacketHeader. The easiest way is probably to use the struct package in Python. Details can be found here:
https://docs.python.org/3/library/struct.html
As a proof of concept, the following will interpret the first 24 bytes:
import struct
data = b'\xe4\x07\x01\x03\x01\x07O\x90.\xea\xc2!7\x16\xa5\xbb\x02C\xda\n\x00\x00\x00\xff\x01\x00\x03:\x00\x00\x00 A\x00\x00\xdcB\xb5+\xc1#\xc82\xcc\x10\t\x00\xd9\x00\x00\x00\x00\x00\x12\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00$tJ\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
#Note that I am only taking the first 24 bytes. You must pass data that is
#the appropriate length to the unpack function. We don't know what everything
#else is until after we parse out the header
header = struct.unpack('<HBBBBQfIBB', data[:24])
print(header)
You basically want to read the first 24 bytes to get the header of the message. From there, you need to use the m_packetId field to determine what the rest of the message is. As an example, this particular packet has a packetId of 7, which is a "Car Status" packet. So you would look at the packing format for the struct CarStatus further down on that page to figure out how to interpret the rest of the message. Rinse and repeat as data arrives.
Update: In the format string, the < tells you to interpret the bytes as little-endian with no alignment (based on the fact that the documentation says it is little-endian and packed). I would recommend reading through the entire section on Format Characters in the documentation above to fully understand what all is happening regarding alignment, but in a nutshell it will try to align those bytes with their representation in memory, which may not match exactly the format you specify. In this case, HBBBBQ takes up 2 bytes more than you'd expect. This is because your computer will try to pack structs in memory so that they are word-aligned. Your computer architecture determines the word alignment (on a 64-bit computer, words are 64-bits, or 8 bytes, long). A Q takes a full word, so the packer will try to align everything before the Q to a word. However, HBBBB only requires 6 bytes; so, Python will, by default, pad an extra 2 bytes to make sure everything lines up. Using < at the front both ensures that the bytes will be interpreted in the correct order, and that it won't try to align the bytes.
Just for information if someone else is looking for this. In python there is the library f1-2019-telemetry existing. On the documentation, there is a missing part about the "how to use" so here is a snippet:
from f1_2020_telemetry.packets import *
...
udp_socket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
udp_socket.bind((host, port))
while True:
udp_packet = udp_socket.recv(2048)
packet = unpack_udp_packet(udp_packet)
if isinstance(packet, PacketSessionData_V1): # refer to doc for classes / attribute
print(packet.trackTemperature) # for example
if isinstance(packet, PacketParticipantsData_V1):
for i, participant in enumerate(packet.participants):
print(DriverIDs[participant.driverId]) # the library has some mapping for pilot name / track name / ...
Regards,
Nicolas
I am trying to recreate a disk image manually through bash. I have an empty disk the same size as the original and I am trying to insert each file at same address as the original disk so that both hash's match. However I cant seem to find the commands to do this. I was advised to use DD or DCFLDD but I cant figure out how to do this with the documentation online. I have a disk, image.dmg and the first file is ._.Trashes with an inode of 4 and size of 4096 bytes.
With dd you may like to use the following arguments:
bs=BYTES
read and write up to BYTES bytes at a time
count=N
copy only N input blocks
seek=N skip N obs-sized blocks at start of output
skip=N skip N ibs-sized blocks at start of input
In other words, to copy N bytes at offset X in file A to offset Y in file B, something like the following should do:
dd bs=1 count=N if=A skip=X of=B seek=Y
I have a problem with startRFC.exe that produces much bigger network-traffic than required. startRFC has 3 parameters = 3 internal tables = 3 CSV files. Total size of these files that are sent to SAP is 3MB, but it takes 15minutes and totally is uploaded 150MBs.
Has anyone experienced this?
POSSIBLE SOLUTION: So it seams that our traffic 150MB was correct although filesize was only 3MB. Problem is that if there is in startRFC defined row-length 1300 (for an Internal Table), startRFC automatically padds all rows with spaces to the max-length. We had cca 6000 rows per 13000 characters = 78MB if 1 char = 1 byte. If 1 char = 2 bytes then 150MB is obvious result
I have a socket server listening for UDP packets from a GSM device. Some of the data comes in as multibytes, such as time, which requires multibytes for accuracy. This is an example:
179,248,164,14
The bytes are represented in decimal notation. My goal is to convert that into seconds:
245692595
I am trying to do that and was told:
"You must take those 4 bytes and place them into a single long integer in little endian format. If you are using Python to read and encode the data, you will need to look at using the .read() and struct.unpack() methods to successfully convert it to an integer. The resulting value is the number of seconds since 01/01/2000."
So, I tried to do this:
%w(179 248 164 14).sort.map(&:to_i).inject(&:+)
=> 605
And I obviously am getting the wrong answer.
You should use the pack and unpack methods to do this:
[179,248,164,14].pack('C*').unpack('I')[0]
# => 245692595
It's not about adding them together, though. You're doing the math wrong. The correct way to do it with inject is this:
[179,248,164,14].reverse.inject { |s,v| s * 256 + v }
# => 245692595
Note you will have to account for byte ordering when representing binary numbers that are more than one byte long.
If the original data is already a binary string you won't have to perform the pack operation and can proceed directly to the unpack phase.