Find Jobs
Hire Freelancers

Calculated Field from Array

$10-15 USD

Cerrado
Publicado hace más de 8 años

$10-15 USD

Pagado a la entrega
I'm attempting to create a new mapping in an array using a calculation between to existing mappings. Example: '(space/total_space)' => [ 'key' => 'Disk_Free_Percentage', ], Where 'space' is divided by 'total_space' to get a percentage. The code I am using this far is below and I am stuck on this last piece. Any help or pointers would be greatly appreciated. // Call API to get servers $rawData = $admin->servers(); // Data mapping $map = [ 'server_name' => [ 'key' => 'Node', ], 'space' => [ 'key' => 'Disk_Free_GB', ], 'total_space' => [ 'key' => 'Total_Disk_GB', ], 'ram' => [ 'key' => 'Free_RAM_GB', 'normalize' => function ($data) { return number_format($data / 1024, 2); }, ], 'total_ram' => [ 'key' => 'Total_RAM_GB', 'normalize' => function ($data) { return number_format($data / 1024, 2); }, ], 'numvps' => [ 'key' => 'VMs', ], 'version' => [ 'key' => 'Version', ], ]; // Remap data $data = []; foreach ($rawData['servs'] as $row) { $item = []; foreach ($map as $fieldName => $field) { // Validate key exists if (!isset($field['key'])) { throw new LogicException(sprintf('Field %s must supply a key', $fieldName)); } // Get data from API if (isset($row[$fieldName])) { $value = $row[$fieldName]; } else { // Use null if data not given by API $value = null; } // Run normalize where set if (isset($field['normalize']) && is_callable($field['normalize'])) { $value = call_user_func($field['normalize'], $value); } // Map to new data $item[$field['key']] = $value; } $data[] = $item; } // encode JSON $json = json_encode($data)
ID del proyecto: 9047097

Información sobre el proyecto

4 propuestas
Proyecto remoto
Activo hace 8 años

¿Buscas ganar dinero?

Beneficios de presentar ofertas en Freelancer

Fija tu plazo y presupuesto
Cobra por tu trabajo
Describe tu propuesta
Es gratis registrarse y presentar ofertas en los trabajos
4 freelancers están ofertando un promedio de $42 USD por este trabajo
Avatar del usuario
Hi there I can do this calculation for you. You can see my track record. I can finish this job in the next hour. Looking forward to hear from you. Thanks Rinsad
$20 USD en 0 día
4,9 (1089 comentarios)
8,9
8,9
Avatar del usuario
Hello! With 98% to 99% completion rate, 850+ successfully completed projects, and a 4.99 reputation (maximum possible, 5.0) (can be verified on my profile page https://www.freelancer.com/u/rajeshsonisl.html !!)... you can never go wrong choosing me :) I am available to get started on your project right away. I look forward to your reply. Thanks. Kind Regards, Rajesh Soni
$19 USD en 1 día
5,0 (955 comentarios)
8,7
8,7
Avatar del usuario
Dear sir, I will complete your project asap, LIFETIME error free guarantee and provide ONE YEAR support... I have right Skills required PHP, Software Architecture to execute your esteemed project.
$39 USD en 1 día
5,0 (113 comentarios)
6,7
6,7
Avatar del usuario
Dear Sir we are capable of performing the required task perfectly with accuracy, please let us know if you want to clarify in details.. if you want us to share our skill and previous work please initiate the chat by replying.. hope to hear you soon.. -- Thanks & Regards Moumita
$89 USD en 1 día
4,8 (78 comentarios)
6,3
6,3

Sobre este cliente

Bandera de UNITED STATES
United States
0,0
0
Miembro desde dic 3, 2015

Verificación del cliente

¡Gracias! Te hemos enviado un enlace para reclamar tu crédito gratuito.
Algo salió mal al enviar tu correo electrónico. Por favor, intenta de nuevo.
Usuarios registrados Total de empleos publicados
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Cargando visualización previa
Permiso concedido para Geolocalización.
Tu sesión de acceso ha expirado y has sido desconectado. Por favor, inica sesión nuevamente.